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

JVM stdin/stdout cannot be set to named pipe

    XMLWordPrintable

Details

    • Fix Understood
    • sparc
    • solaris_8

    Description


      When redirecting JVM stdin/stdout to a named pipe (or even to the
      same file), and the I/O stream is read or written using standard
      Java I/O mechanism, for example, with BufferedReader.read() layered
      above System.in and System.out (streams), an exception is thrown:


      IOException: Bad File Number.

      This is probably related to the same core issues affecting bug 4410664,
      and seems to have to do with the way the JVM is dealing with file
      descriptors, and some faulty logic about what file I/O means on UNIX.

      For example, running the attached program without redirecting stdin/stdout
      causes it to echo lines that are typed at the keyboard. This is correct,
      expected and correct behavior. It behaves like typing 'cat' at the prompt,
      with no arguments, would.

      If the attached program is run with I/O redirected, the previously mentioned
      exception is thrown. This was going to be the next-best workaround for the
      problem in bug 4410664. The command to reproduce the problem (after compiling
      the attachment) is:

      % java PipeDream >pipe_to_something_that_talks_back 0>&1
      Error reading from pipe
      java.io.IOException: Bad file number

      The attached program, PipeDream.java, is also included here:

      import java.io.*;

      public class PipeDream {

       public static void main(String args[]) {
        
            BufferedWriter dmPipeOut =
         new BufferedWriter(
      new OutputStreamWriter(System.out));

            BufferedReader dmPipeIn =
                  new BufferedReader(
      new InputStreamReader(System.in));

            try {
               dmPipeOut.write("Some arbitrary string\n");
            } catch (Exception e) {
      System.err.println("Error writing data to pipe");
      System.err.println(e.toString());
      System.exit(-1);
            }
           
            try {
      String buf = null;
      while ((buf = dmPipeIn.readLine()) != null)
            System.out.println(buf);
            } catch (Exception e) {
      System.err.println("Error reading from pipe");
      System.err.println(e.toString());
      System.exit(-1);
            }
        }
      }



      Attachments

        Issue Links

          Activity

            People

              mr Mark Reinhold
              duke J. Duke
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Imported:
                Indexed: