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

Runtime.exec() leaks pipe to child process

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 1.1.4
    • Fix Version/s: 1.2.0
    • Component/s: hotspot
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      1.2beta4
    • CPU:
      x86
    • OS:
      windows_nt
    • Verification:
      Not verified

      Description



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

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: