Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4093815

Runtime.exec() leaks pipe to child process

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.2.0
    • 1.1.4
    • hotspot
    • 1.2beta4
    • x86
    • windows_nt
    • Not verified



      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)
      ======================================================================

            hongzh Hong Zhang
            bklocksunw Brian Klock (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: