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

Runtime.exec() hangs on Linux

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P1 P1
    • None
    • 1.3.1, 1.4.0
    • core-libs

      If earlier exec() call fails (IOException), subsequent exec() call never returns.

      Test Scenario:

            1. Exec1() generates IO exception (as expected).
            2. When Exec2() is called, control never returns back (program hangs).

      This happens on Linux (red hat linux 6.2). Works OK on Solaris and Windows.

      (build 1.4.0beta-b40)
            
      // ------------------- Test.java -------------------
      class Test {

          public static void main(String[] args) {

      Test t = new Test();

      t.Exec1(); // should generate IO exception
      t.Exec2();
             
          }

          void Exec1() {
      try {
      String cmd ;
      cmd = "invalid";
      Process process = Runtime.getRuntime().exec(cmd);
      } catch (Exception e) {
      e.printStackTrace();
      }

          }

          void Exec2() {
      try {
      String cmd ;
      cmd = "ls";
      Process process = Runtime.getRuntime().exec(cmd);

                  InputStream in = process.getInputStream();
                  DataInputStream din = new DataInputStream(in);
      BufferedReader br
                            = new BufferedReader(new InputStreamReader(in));
                  String s;
                 
                  while ((s = br.readLine()) != null) {
      System.out.println(s);
                  }
                 

      } catch (Exception e) {
      e.printStackTrace();
      }
          }
      }

      // --------------------------------------

            mr Mark Reinhold
            hvilekar Harshad Vilekar (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: