我有一个在 linux 和 windows ftp 服务器之间传输文件的 C#.Net 控制台应用程序代码。
代码的行为是我自动打开一个控制台来显示文件传输的状态。在与 Windows 服务器之间传输文件时,我需要显示文件传输正在进行的指示器(使用看起来像是在移动或转动的符号)。这些符号如下:“|” --> "/" --> "-" --> "\" --> "|"
使用以下代码在 C#.Net 中显示上述“指标/符号”没有问题:
ProcessStartInfo PSI = new ProcessStartInfo("CMD.exe", "/C [here is the call to psftp / ftp scripts]"); 
String SymbolChar = "|";
Process proc = Process.Start(PSI); 
        while (true)
        {
            Thread.sleep(20);
            if (proc.HasExited)
            {
                Console.WriteLine("\b-> Done\n");
                break;
            }
            else
            {
                SymbolChar = NextChar(SymbolChar);
                Console.Write("\b{0}", SymbolChar);
            }
        }
        StreamReader srError = proc.StandardError;
        StreamReader srOutput = proc.StandardOutput;
//method used to animate status during process
    private static String NextChar(String sCurrentChar)
    {
        String sTempChar = "";
        if (sCurrentChar.equals("|")) {
            sTempChar = "/";
        }
        else if (sCurrentChar.equals("/")) {
            sTempChar = "-";
        }
        else if (sCurrentChar.equals("-")) {
            sTempChar = "\\";
        }
        else if (sCurrentChar.equals("-")) {
            sTempChar = "\\";
        }
        else if (sCurrentChar.equals("\\")) {
            sTempChar = "|";
        }
        return sTempChar;
    }
当我使用以下代码将上述代码转换为 java 时,我的问题就开始了:
String sParam = "bash " + [here is the call to psftp / ftp scripts];
String cmd[] = {"/bin/bash","-c",sParam};
Process proc = Runtime.getRuntime().exec(cmd);
上面的代码完美运行。问题是我不知道如何显示“动画”字符了。我突然不知道(我非常需要帮助)如何转换它:
Process proc = Process.Start(PSI); 
        while (true)
        {
            Thread.sleep(20);
            if (proc.HasExited)
            {
                Console.WriteLine("\b-> Done\n");
                break;
            }
            else
            {
                SymbolChar = NextChar(SymbolChar);
                Console.Write("\b{0}", SymbolChar);
            }
        }
您对我可以在 java 中的“if (proc.HasExited)”行中使用什么以便继续前进有任何想法吗?
抱歉,解释太长了。我真的,真的需要帮助。
非常感谢您!