java.lang.Runtime exec() programs works on solaris and hangs on windows
Test Program: TestMain.java and Test.java
----------------------
import java.util.prefs.*;
import java.util.*;
import java.io.*;
public class TestMain {
static final int TOTAL = 11;
public static void main(String[] args) throws Exception {
try {
String cmds = "java Test";
//exec proces01
Process processP1 = Runtime.getRuntime().exec(cmds);
InputStream inP1 = processP1.getInputStream();
DataInputStream dinP1 = new DataInputStream(inP1);
String lineP1 [] = new String[TOTAL+1];
int intP1 = 0;
try {
processP1.waitFor();
} catch (InterruptedException e) {
System.out.println ("InterruptedException thrown in TestMain failed " + e);
e.printStackTrace();
}
System.out.println("processP1.exitValue() exited with " + processP1.exitValue());
if (processP1.exitValue() !=0) {
throw new Exception("processP1.exitValue() !=0 in TestMain");
}
while ((lineP1[intP1] = dinP1.readLine()) != null) {
System.out.println("got string from Test = " + lineP1[intP1]);
intP1++;
}
inP1.close();
dinP1.close();
System.out.println("TestMain passed");
} catch (Exception e) {
System.out.println (" Exception thrown in TestMain failed " + e);
e.printStackTrace();
}
}
}
----------------------------Test.java--------------
import java.util.prefs.*;
import java.util.*;
public class Test {
static final int TOTAL = 11;
public static void main(String[] args) throws Exception {
for (int i=0; i<TOTAL; i++) {
System.out.println(i);
}
}
}
--------------------result on solaris works ---------
javasupport2:/home/pande/merlin/bugs/runtime 114 % java TestMain
processP1.exitValue() exited with 0
got string from Test = 0
got string from Test = 1
got string from Test = 2
got string from Test = 3
got string from Test = 4
got string from Test = 5
got string from Test = 6
got string from Test = 7
got string from Test = 8
got string from Test = 9
got string from Test = 10
TestMain passed
-----------------------------on windowsNT hangs-------------------
--------------------
Test Program: TestMain.java and Test.java
----------------------
import java.util.prefs.*;
import java.util.*;
import java.io.*;
public class TestMain {
static final int TOTAL = 11;
public static void main(String[] args) throws Exception {
try {
String cmds = "java Test";
//exec proces01
Process processP1 = Runtime.getRuntime().exec(cmds);
InputStream inP1 = processP1.getInputStream();
DataInputStream dinP1 = new DataInputStream(inP1);
String lineP1 [] = new String[TOTAL+1];
int intP1 = 0;
try {
processP1.waitFor();
} catch (InterruptedException e) {
System.out.println ("InterruptedException thrown in TestMain failed " + e);
e.printStackTrace();
}
System.out.println("processP1.exitValue() exited with " + processP1.exitValue());
if (processP1.exitValue() !=0) {
throw new Exception("processP1.exitValue() !=0 in TestMain");
}
while ((lineP1[intP1] = dinP1.readLine()) != null) {
System.out.println("got string from Test = " + lineP1[intP1]);
intP1++;
}
inP1.close();
dinP1.close();
System.out.println("TestMain passed");
} catch (Exception e) {
System.out.println (" Exception thrown in TestMain failed " + e);
e.printStackTrace();
}
}
}
----------------------------Test.java--------------
import java.util.prefs.*;
import java.util.*;
public class Test {
static final int TOTAL = 11;
public static void main(String[] args) throws Exception {
for (int i=0; i<TOTAL; i++) {
System.out.println(i);
}
}
}
--------------------result on solaris works ---------
javasupport2:/home/pande/merlin/bugs/runtime 114 % java TestMain
processP1.exitValue() exited with 0
got string from Test = 0
got string from Test = 1
got string from Test = 2
got string from Test = 3
got string from Test = 4
got string from Test = 5
got string from Test = 6
got string from Test = 7
got string from Test = 8
got string from Test = 9
got string from Test = 10
TestMain passed
-----------------------------on windowsNT hangs-------------------
--------------------