-
Bug
-
Resolution: Fixed
-
P1
-
1.1
-
1.1
-
sparc
-
solaris_2.4
-
Not verified
VM hangs after executing new Process please check attached program for recreating problem. This works fine in JDK1.1 Alpha build and previous releases.
I am running latest JDK1.1M.
To compile use command javac TestExec.java
and run command as follows:
java TestExec `which javac`
And observe that VM never exits. This will cause any program that waits for
VM to close stderr and stdout streams.
------------8<------------TestExec.java -----------------------
import java.io.*;
import java.awt.*;
class DisplayThread extends Thread {
DataInputStream inStream;
/**
* Constructor
*/
DisplayThread(DataInputStream stream){
inStream = stream;
}
protected void display(String line) {
System.out.println(line);
}
public void run() {
String Line;
try {
while ((Line = inStream.readLine()) != null ) {
display(Line);
}
}
catch (IOException i) { // Ignore exception
}
}
}
public class TestExec {
private DataInputStream stdout,
stderr;
private DataOutputStream stdin;
private Process newProc;
protected DisplayThread dispStdout,
dispStderr;
TestExec(String[] shellCmds) {
try {
// Get new runtime
newProc = Runtime.getRuntime().exec(shellCmds);
// Bind stderr First
stderr = new DataInputStream(
new BufferedInputStream(newProc.getErrorStream(),1024));
// Bind stdout
stdout = new DataInputStream(
new BufferedInputStream(newProc.getInputStream(),1024));
// Bind stdin
stdin = new DataOutputStream(
new BufferedOutputStream(newProc.getOutputStream()));
String Line;
// Start Display Thread for Printing Messages in Background
displayStdout(stdout);
displayStderr(stderr);
newProc.waitFor();
System.out.println("Exit Value :" + newProc.exitValue());
}
catch (Exception i) {
System.out.println(i);
}
}
// This is interface that subclass can modify for stdout and stderr
protected void displayStdout(DataInputStream stdout) {
dispStdout = new DisplayThread(stdout);
dispStdout.start();
}
// Display stdError
protected void displayStderr(DataInputStream stderr) {
dispStderr = new DisplayThread(stderr);
dispStderr.start();
}
public static void main(String[] args) {
System.out.println("Executing command :" + args[0]);
TestExec t = new TestExec(args);
System.out.println("Completed Successfully");
}
}
I am running latest JDK1.1M.
To compile use command javac TestExec.java
and run command as follows:
java TestExec `which javac`
And observe that VM never exits. This will cause any program that waits for
VM to close stderr and stdout streams.
------------8<------------TestExec.java -----------------------
import java.io.*;
import java.awt.*;
class DisplayThread extends Thread {
DataInputStream inStream;
/**
* Constructor
*/
DisplayThread(DataInputStream stream){
inStream = stream;
}
protected void display(String line) {
System.out.println(line);
}
public void run() {
String Line;
try {
while ((Line = inStream.readLine()) != null ) {
display(Line);
}
}
catch (IOException i) { // Ignore exception
}
}
}
public class TestExec {
private DataInputStream stdout,
stderr;
private DataOutputStream stdin;
private Process newProc;
protected DisplayThread dispStdout,
dispStderr;
TestExec(String[] shellCmds) {
try {
// Get new runtime
newProc = Runtime.getRuntime().exec(shellCmds);
// Bind stderr First
stderr = new DataInputStream(
new BufferedInputStream(newProc.getErrorStream(),1024));
// Bind stdout
stdout = new DataInputStream(
new BufferedInputStream(newProc.getInputStream(),1024));
// Bind stdin
stdin = new DataOutputStream(
new BufferedOutputStream(newProc.getOutputStream()));
String Line;
// Start Display Thread for Printing Messages in Background
displayStdout(stdout);
displayStderr(stderr);
newProc.waitFor();
System.out.println("Exit Value :" + newProc.exitValue());
}
catch (Exception i) {
System.out.println(i);
}
}
// This is interface that subclass can modify for stdout and stderr
protected void displayStdout(DataInputStream stdout) {
dispStdout = new DisplayThread(stdout);
dispStdout.start();
}
// Display stdError
protected void displayStderr(DataInputStream stderr) {
dispStderr = new DisplayThread(stderr);
dispStderr.start();
}
public static void main(String[] args) {
System.out.println("Executing command :" + args[0]);
TestExec t = new TestExec(args);
System.out.println("Completed Successfully");
}
}
- relates to
-
JDK-4014551 no EOF from child Process?
-
- Closed
-