JDK-8023130 : (process) ProcessBuilder#inheritIO does not work on Windows
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 7
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_7
  • CPU: x86
  • Submitted: 2012-09-15
  • Updated: 2015-01-20
  • Resolved: 2013-09-23
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.
JDK 7 JDK 8
7u60Fixed 8 b110Fixed
Related Reports
Relates :  
Relates :  
Relates :  
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
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
04-12-2013

Esc bug.
20-09-2013

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.
19-08-2013

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.
19-08-2013

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.
19-08-2013

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.
19-08-2013

There are jdk unit tests and JCK tests for this method so surprising to hear that it is not working.
18-08-2013

The bug is confirmed with the latest jdk8 b103.
18-08-2013