Name: skT88420 Date: 06/07/99
RESUBMISSION, see '*****' for revisions. Using javaw, when starting from a Windows shortcut, (does not occur when running from a command line prompt), a console window opens when Runtime exec creates a native process even though all output streams are connected to the parent process. This console remains blank as the process runs.
The description of class Process says: "The created subprocess does not have its own terminal or console. All its standard io (i.e. stdin, stdout, stderr) operations will be redirected to the parent process through three streams ..."
This did not occur using jrew under jdk 1.x. This problem has been seen on Win 95 and Win NT 4.0.
java version "1.2.1"
Classic VM (build JDK-1.2.1-A, native threads)
java full version "JDK-1.2.1-A"
To demonstrate the problem use the source code supplied below and follow these steps (modify per your configuration),
***** Create a Windows shortcut with the Target:
c:\jdk1.2.1\bin\javaw.exe ProcessRunWindow find \"doesn't matter\" c:\*
and the Start In:
(the location of ProcessRunWindow.java)
***** Perform the test with the run option kept "Normal window". This test shows the problem seen in a much larger application. It is not possible to run this application minimized.
Compile ProcessRunWindow then click on the shortcut.
The program runs showing the output of the "find" command in the window, but an MSDOS console window also opens, with the title "...find.exe", and displays nothing. This console window should not open. ***** Depending on your machine, the dosbox may flash by pretty quickly, you may miss it the first time. To see it better change the command to search a more populated directory.
SOURCE CODE:
import java.awt.*;
import java.io.*;
import java.util.*;
/**
* ProcessRunWindow
* @version
* @author
* Demonstrates Java 1.2.1 problem on Windows
* Create a shortcut with the Target:
* \jdk1.2.1\bin\javaw.exe -cp . ProcessRunWindow find \"thread\" *.java
* Set the Start In:
* (the location of ProcessRunWindow.java)
* Compile ProcessRunWindow the click on the shortcut.
* The program runs showing the output of the "find" command in the window,
* but an MSDOS console window opens, with the title " ...find.exe", and displays
* nothing. This console window should not open.
*/
class ProcessRunWindow extends Frame {
TextArea output;
/**
*
* @param
*/
ProcessRunWindow (String cmd) {
output = new TextArea(5,40);
add(output);
command(cmd);
}
/**
* ProcessRunWindow find \"thread\" \jd\work\*.java
* @param
* @return
*/
public static void main(String[] args) throws Exception {
if (args.length < 1) {
System.err.println("Usage: java ProcessRun cmd");
System.exit(1);
}
String cmd = "";
for (int i=0;i<args.length;i++) cmd += args[i] + " ";
ProcessRunWindow prw = new ProcessRunWindow(cmd);
prw.pack();
prw.show();
}
/**
*
* @param
* @return
*/
void command (String cmd) {
Process p=null;
Runtime rt = Runtime.getRuntime();
try {
p = rt.exec(cmd);
} catch (IOException ex) {
System.err.println("Error on command: "+cmd+"; "+ex);
return;
}
final DataInputStream dis = new DataInputStream(p.getInputStream());
final DataInputStream des = new DataInputStream(p.getErrorStream());
Thread thread = new Thread("input stream") {
public void run() {
try {
String line=null;
while ((line = dis.readLine()) != null) {
if (output==null) System.out.println(line);
else output.appendText(line+"\n");
}
}
catch (IOException e) {
System.err.println(e);
}
}
};
thread.start();
Thread thread2 = new Thread("error stream") {
public void run() {
try {
String line=null;
while ((line = des.readLine()) != null) {
if (output==null) System.out.println(line);
else output.appendText(line+"\n");
}
}
catch (IOException e) {
System.err.println(e);
}
}
};
thread2.start();
}
/**
*
* @param
* @return
*/
public boolean handleEvent(Event event) {
if (event.id == Event.WINDOW_DESTROY) {
System.exit(0);
}
return super.handleEvent(event);
}
}
(Review ID: 84039)
======================================================================