RFR [8023130] (process) ProcessBuilder#inheritIO does not work on Windows

Ivan Gerasimov ivan.gerasimov at oracle.com
Fri Aug 23 16:11:25 UTC 2013


Thank you Alan!

On 23.08.2013 14:28, Alan Bateman wrote:
> On 23/08/2013 04:07, Ivan Gerasimov wrote:
>> Hello everybody!
>>
>> The method ProcessBuilder#inheritIO() is reported to not have any 
>> effect on Windows platform.
>> The same story is with redirectOutput/Input/Error(Redirect.INHERIT) 
>> methods.
>> As the result, standard in/out/err aren't inherited.
>>
>> It turn out that the culprit is the 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 with the fix for 
>> http://bugs.sun.com/view_bug.do?bug_id=4244515 to suppress a console 
>> window on a newly created process, when it is created from a program 
>> launched with javaw.exe.
>> Thus, I left this flag only for cases when the program doesn't have a 
>> console associated with it.
>>
>> Would you please help review a fix for this problem?
>>
>> BUGURL: http://bugs.sun.com/view_bug.do?bug_id=8023130
>> WEBREV: http://cr.openjdk.java.net/~igerasim/8023130/0/webrev/
>>
> Good sleuthing!
>
> Just so I understand, if we have a console (DOS command window for 
> example) then will dropping CREATE_NO_WINDOW result in a new window or 
> not?
>
No new console for a console application without CREATE_NO_WINDOW flag.
I used a sample program to confirm that:
---------------
class InheritIO {
     public static void main(String[] args) throws Exception {
         int err = new 
ProcessBuilder(args).inheritIO().redirectErrorStream(true).start().waitFor();
         System.err.println("Exit value: " + err);
     }
}
---------------
With the proposed fix running it as '> java InheritIO cmd /?' copies the 
output of the command to the existing console.
No new console is created.

> One thing that it does highlight is that the coverage for inherit in 
> ProcessBuilder/Basic.java was not sufficient as this should have been 
> caught a long time ago. My preference would be to add to this test 
> rather than introduce a new one (ProcessBuilder.java is Martin's 
> original mother-of-all tests for ProcessBuilder).
>
Yes, I agree. It would be better to integrate this test into Basic.java.

Sincerely yours,
Ivan

> -Alan.
>
>




More information about the core-libs-dev mailing list