JDK-4093815 : Runtime.exec() leaks pipe to child process
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 1.1.4
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_nt
  • CPU: x86
  • Submitted: 1997-11-18
  • Updated: 1999-01-15
  • Resolved: 1999-01-15
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.
1.2.0 1.2beta4Fixed
Related Reports
Relates :  

Name: bk70084			Date: 11/18/97

My child processes never terminate.

Under Windows NT 4.0, the child process NEVER
detects end-of-file on its input pipe.

I believe this is because a handle for 
the writing end of the pipe is inherited by
the child process.  This would occur if the
the Java application did NOT make the the
handle for the writing end of the pipe 
UNinheritable.  After CreatePipe, it's necessary
to invoke 
(This would depend on which of the pipes you're
manipulating, and whether you are telling
CreatePipe to make inheritable handles.)

Here is code to reproduce the problem
--- StartChild.java ---
import java.lang.*;
import java.io.IOException;
import java.io.Writer;
import java.io.OutputStreamWriter;

class StartChild
    public static void main(String args[])
	    throws IOException
	Process child = Runtime.getRuntime().exec(args);
	Writer out = new OutputStreamWriter(child.getOutputStream());
	out.write("This is from java.\n");
--- readstdin.c ---
#include <stdio.h>

int main(int argc, char **argv)
    int input;
    if (argc > 1)
	freopen(argv[1], "a", stdout);
    while(EOF != (input = getchar()))
Of course, you could use something like cat 
instead of my little C code.  Invoke with

java StartChild readstdin
(Review ID: 20071)

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: generic FIXED IN: 1.2beta4 INTEGRATED IN: 1.2beta4

EVALUATION The description is correct. On unix, it is done by closing all file descriptors except stdin, stdout, and stderr. ###@###.### 1998-02-13

SUGGESTED FIX Mark the write handle to stdin, and read handles to stdout and stderr as non-inheritable. ###@###.### 1998-02-13