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

Linux: IO redirection fails

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P1 P1
    • None
    • 1.3.1
    • hotspot
    • None
    • x86
    • linux


      Symptoms: read hangs even if the buffer has bytes in it.



      [tester@tralus volkov]$ export PATH=/net/sqesvr/export/vsn/users/merlin/jdk1.3.1/linux-i386/bin:$PATH

      [tester@tralus volkov]$ java -version
      java version "1.3.1ea"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1ea-b01)

      [tester@tralus volkov]$ uname -a
      Linux tralus.eng.sun.com 2.2.14-5.0 #1 Tue Mar 7 21:07:39 EST 2000 i686 unknown

      //============================================================
      import java.io.*;

      public class Test {
          
          public void delay() {
              System.out.println("Sleeping");
              for (int i = 0;i < 1000000000;i++) ;
              
          }
      // There are tow tests here. One is called if first argument is "one".
      // It starts additiona thread and exeutes ls command.
      // Second one executes "ls" with out thrad.
      //
          public static void main(String[] argv) {
              String test = "one";
              if (argv != null && argv[0] != null)
                  test = argv[0];
              Test ts = new Test();
      // Run rn = new Run("/bin/sh -c /bin/echo");
              Run rn = new Run("/bin/sh -c /bin/ls /etc /usr /usr/X11 2>&1");
              if (test.compareTo("one") == 0) {
                  Thread th = new Thread(rn);
                  
                  System.out.println("Starting");
                  th.start();
                  
                  ts.delay();
                  rn.kill();
                  try {
                      System.out.println("Joinnig");
                      th.join();
                  } catch (Exception e) {
                      System.out.println("Exception: " + e.getMessage());
                      e.printStackTrace();
                  }
              } else {
                  rn.run();
              }
          }
      }

      class Run implements Runnable {
          private String argv = null;
          private Process ps = null;

          public Run(String str) {
              argv = str;
          }

          public void run() {
              System.out.println("Started: ");
              try {
                  ps = Runtime.getRuntime().exec(argv);
              } catch (Exception e) {
                  System.out.println("Exception: " + e.getMessage());
                  e.printStackTrace();
              }
              InputStream is = ps.getInputStream();
              byte buff[] = new byte[256];
              int res = 0;
              System.out.println("================ Output: ================");
              try {
      // Test hangs here on the very first read.
                  while ((res = is.read(buff, 0, 256)) != -1) {
                      System.out.println(new String(buff, 0, res));
                  }
              } catch (Exception e) {}
              System.out.println("================ ======= ================");
          }

          public void kill() {
              ps.destroy();
          }
      }

      alexei.volkov@eng 2000-09-26

            duke J. Duke
            avolkovorcl Alexei Volkov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: