United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-8023130 : (process) ProcessBuilder#inheritIO does not work on Windows

Details
Type:
Bug
Submit Date:
2012-09-15
Status:
Closed
Updated Date:
2014-12-17
Project Name:
JDK
Resolved Date:
2013-09-23
Component:
core-libs
OS:
windows_7
Sub-Component:
java.lang
CPU:
x86
Priority:
P2
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:

Related Reports
Backport:
Backport:
Relates:
Relates:

Sub Tasks

Description
FULL PRODUCT VERSION :
java version "1.7.0_07"
Java(TM) SE Runtime Environment (build 1.7.0_07-b11)
Java HotSpot(TM) 64-Bit Server VM (build 23.3-b01, mixed mode, sharing)


ADDITIONAL OS VERSION INFORMATION :
Windows 7 64-bit
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
Running an external process using java.lang.ProcessBuilder's inheritIO method to cause the standard streams to be inherited does not work. The external process's output does not appear in the invoking process's output.

Fails as described on both my Windows 7 64-bit and my Vista 32-bit.
Works fine on Ubuntu Linux (using "ls" and a few other commands).

Inheriting via redirectOutput(Redirect.INHERIT) fails too.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Using my little test program (below),
Run:
  java InheritIO command-words...
Example:
  java InheritIO fc
  ("fc" is an executable that is on all Windows systems, but use any command that produces output)

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Using the FC command as in my example above, I would expect:
--------
FC: Insufficient number of file specifications
Exit value: -1
-------
ACTUAL -
--------
Exit value: -1
-------

ERROR MESSAGES/STACK TRACES THAT OCCUR :
No error messages.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
class InheritIO {
    public static void main(String[] args) throws Exception {
        int err = new ProcessBuilder(args).inheritIO().start().waitFor();
        System.err.println("Exit value: " + err);
    }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Revert to the old way of copying the streams myself!

                                    

Comments
URL:   http://hg.openjdk.java.net/jdk8/jdk8/jdk/rev/56d247821694
User:  lana
Date:  2013-10-01 17:37:37 +0000

                                     
2013-10-01
URL:   http://hg.openjdk.java.net/jdk8/tl/jdk/rev/56d247821694
User:  alanb
Date:  2013-09-23 03:09:25 +0000

                                     
2013-09-23
Notes to QA:

The automatic regression test can show false positive, i.e. not catch the fault.
To reliably check the fix, please follow the instruction from the bug description:

1) create a java file named InheritIO.java with the following content:
----------------------
class InheritIO {
    public static void main(String[] args) throws Exception {
        int err = new ProcessBuilder(args).inheritIO().start().waitFor();
        System.err.println("Exit value: " + err);
    }
}
----------------------
2) compile it with the tested jdk's javac

\pathtojdk\bin\javac InheritIO.java

3) run the compiled program with the tested jdk's java

\pathtojdk\bin\java InheritIO fc

4) if you see the following:
----------------------
FC: Insufficient number of file specifications
Exit value: -1
----------------------
then the test pass

if you only see the line with the exit value:
----------------------
Exit value: -1
----------------------
then the test failed
                                     
2013-09-20
Esc bug.
                                     
2013-09-20
Yes, that's very strange.
I've checked different versions and it seems that it didn't work from the very beginning (jdk7.0.1_b08 is the earliest I've checked).
People on different forums have complained for more than a year about non-working inheritIO().
It's hard to believe that nobody in Oracle has ever tested this function on Windows.
There might be some confusion here.
                                     
2013-08-19
It seems I found the culprit and it is CREATE_NO_WINDOW flag passed to CreateProcessW().
MS doc says about this flag: "The process is a console application that is being run without a console window."

CREATE_NO_WINDOW flag was added to suppress a console window on a newly created process, when it was created from a program launched with javaw.exe.
                                     
2013-08-19
The only place where inheritIO() is tested in jtreg tests is java/lang/ProcessBuilder/Basic.java.
-----------------------
                ProcessBuilder pb = new ProcessBuilder(childArgs);
                pb.inheritIO();
                ProcessResults r = run(pb);
                if (! r.out().equals(""))
                    System.exit(7);
                if (! r.err().equals(""))
                    System.exit(8);
-----------------------
r.out() above is what was read from pb.start().getInputStream().
Thus, the test confirms that content read was empty.

I tried to put a 5 second delay before waitFor(), doesn't make difference.
I also tried to run a command that produces lots of output (more than 1Mb), no difference either.
Thus, this is not buffering/timing.

                                     
2013-08-19
It's tested on Windows every day (in JPRT, TL nightlies, promoted builds, ...).  One thing to check is whether the output/error is printed for cases where the child doesn't terminate immediately, just in case this is a Windows issue with the buffering or timing writing to the pipe. 
                                     
2013-08-19
The bug is confirmed with the latest jdk8 b103.
                                     
2013-08-18
There are jdk unit tests and JCK tests for this method so surprising to hear that it is not working.
                                     
2013-08-18



Hardware and Software, Engineered to Work Together