Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4040341

Process.waitfor () does not return correct value.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P2 P2
    • None
    • 1.1
    • core-libs
    • None
    • sparc
    • solaris_2.4

      Process.waitfor () does not return correct value. In the little example below,
      when "ping" is exec'ed on a standalone machine it should always return an
      exit result of '1', i.e. "failed". Instead, when done repeatedly 'waitfor'
      returns a semi-random sequence of 1's and 0's.

      =====================================
      import java.lang.Runtime;
      import java.lang.Process;

      public class Test {
        
        public static void main (String args[])
          {
            String execArgs[] = {"ping", "webcache.eng", "3"};
            Process proc;
            byte buffer[] = new byte[1024];

            try {
              while (true) {
                proc = Runtime.getRuntime().exec (execArgs);
                int result = proc.waitFor ();
                System.out.print ("Ping = " + result + " -- ");
                System.out.write (buffer, 0, proc.getInputStream().read(buffer));
                proc.destroy ();
              }
            } catch (java.io.IOException ex) {
              return;
            } catch (java.lang.InterruptedException ex) {
              return;
            }
          }
      }

            never Tom Rodriguez
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: