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
SetHandleInformation(
WritingHandle,
HANDLE_FLAG_INHERIT,
FALSE
);
(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");
out.close();
}
}
--- 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()))
{
putchar(input);
}
}
-------
Of course, you could use something like cat
instead of my little C code. Invoke with
java StartChild readstdin
(Review ID: 20071)
======================================================================