CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2011
    Posts
    7

    Convert proc.HasExited from C#.Net to Java

    Hi all,

    I have a C#.Net console app code that transfers files between linux and windows ftp servers.

    The code's behavior is that I automatically open a console to display status of the file transfer. While transferring files to and from the windows server, I need to display an indicator that the file transfer is on-going (using symbols that look like they are moving or turning) . These symbols are as follows : "|" --> "/" --> "-" --> "\" --> "|"

    There had been no problem displaying the said "indicator/symbols" in C#.Net using the following codes :

    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;
    }

    My problem started when I converted the said codes into java using the following :

    String sParam = "bash " + [here is the call to psftp / ftp scripts];
    String cmd[] = {"/bin/bash","-c",sParam};
    Process proc = Runtime.getRuntime().exec(cmd);

    Above code is perfectly working.
    Problem is I don't know how to display the "animated" characters anymore.
    I suddenly don't know (and I badly need help on) how to convert this :

    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);
    }
    }

    Do you have any idea as to what I can use for the line "if (proc.HasExited)" in java so that I could move forward?

    Sorry for the long explanation.
    I really, really need help.

    Thank you very much in advance!

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: Convert proc.HasExited from C#.Net to Java

    I am not aware of any way you can provide an animation in the process window from Java whilst waiting for the Process to complete. You could, however, provide your own GUI progress window.

    You can wait for a process to end by calling it's waitFor() method.
    You can poll the process until it has completed by repeatedly calling readLine() on the input stream until it returns null. Note this will block awaiting output from the process.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured