JDK-4244515 : Exec'ed process with javaw on Windows opens a cosole window
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 1.2.0,1.2.2,1.3.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_98,windows_nt
  • CPU: generic,x86
  • Submitted: 1999-06-07
  • Updated: 2013-08-19
  • Resolved: 2001-11-13
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.0 rc1Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description

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) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: generic merlin-rc1 FIXED IN: merlin-rc1 INTEGRATED IN: merlin-rc1
14-06-2004

EVALUATION We can use flag CREATE_NO_WINDOW with CreateProcess to workaround this problem. However, it does not work well on Win9X. ###@###.### 2000-06-29 We are investigating to see if we can have this bug fixed in Merlin (1.4) beta3. ###@###.### 2001-10-02 Fixed in Merlin beta3. -- ###@###.### 2001/10/2 Unfortunately, un-fixed for Merlin beta3. The code snippet on the JDC is indeed interesting. However, it hides everything launched by Runtime.exec(), including native Windows applications. While acceptable for some console applications, and in particular, the code snippet in this bug, it's unacceptable for just about everything else. We continue to ponder this bug. The Runtime API is not rich enough to indicate when, on win32, the developer intends to hide the window that results from spawning a process. ###@###.### 2001-10-18 We use CREATE_NO_WINDOW on NT. Win9X uses the DETACHED_PROCESS flag if a 32 bit windows application is invoked, otherwise the null flag is used as in 1.2. The console window may still flash by for win9X users if they invoke a 16-bit application but we do not know how to work around that. ###@###.### 2001-10-24 The state of this bug is confusing on the JDC bug database, and that is due to the scripts and processes that display those pages. This bug was indeed fixed for Merlin, and should appear in the release that will be available after 1.4 Beta 3. The fix is not in beta 3. Due to compatibility concerns, we strongly suggest that those interested in thus bug download what will probably be 1.4 RC1 and test the functionality that we have fixed. Any issues arising post 1.4 Beta 3 should be brought to our attention quickly. I've set up an alias that can be used. It is: bug4244515(at)sun.com. Replace the "(at)" with a '@' as appropriate. ###@###.### 2001-11-19
19-11-2001