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;
}
}
}
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;
}
}
}
- duplicates
-
JDK-4034808 Runtime exec sometimes returns wrong value from waitFor()
-
- Closed
-