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

Runtime.exec() gives nasty error messages when the program to exec doesn't exist

    • 1.1
    • sparc
    • solaris_2.5
    • Not verified

      When Runtime.exec() is called with a command that doesn't exist, it doesn't return an error, but it does spew lots of nasty-looking error messages to the output. The following code produces the following output:

      import java.io.*;
      public class ExecDemo
      implements Runnable
      {
      static Process p;
      public static void main(String args[])
      {
      try {p = Runtime.getRuntime().exec("fredbob");}
      catch (IOException e)
      {
      System.err.println("exec IO Exception: " + e.toString());
      return;
      }
      Thread it = new Thread(new ExecDemo(0));
      Thread ot = new Thread(new ExecDemo(1));
      Thread et = new Thread(new ExecDemo(2));
      //it.start();
      ot.start();
      et.start();
      try {p.waitFor();}
      catch (InterruptedException e)
      {
      System.err.println("Wait interrupted: " + e.toString());
      }
      System.out.println("Exit value " + p.exitValue());
      }
      int fd;
      public ExecDemo(int fd) {this.fd = fd;}
      public void run()
      {
      OutputStream out;
      InputStream in;
      if (fd == 0)
      {
      out = p.getOutputStream();
      in = System.in;
      }
      else if (fd == 1)
      {
      out = System.out;
      in = p.getInputStream();
      }
      else
      {
      out = System.err;
      in = p.getErrorStream();
      }
      try
      {
      int c;
      while ((c = in.read()) != -1)
      out.write(c);
      }
      catch (IOException e)
      {
      System.err.println("IO Error fd " + fd + ": " + e.toString());
      }
      }
      }




      Script started on Tue Jul 02 18:43:36 1996
      coolant{soule}~/javatest>java ExecDemo
      err = 1!
      exec of "fredbob" failed with errno 2
      SIGABRT 6* abort (generated by abort(3) routine)
          si_signo [6]: SIGABRT 6* abort (generated by abort(3) routine)
          si_errno [0]: Error 0
          si_code [0]: SI_USER [pid: 5806, uid: 33067]
      stackbase=EFFFF97C, stackpointer=EFFFF660

      Full thread dump:
          "Thread-4" (TID:0xee300920, sys_thread_t:0xef430de0) prio=5
          "Finalizer thread" (TID:0xee3003b0, sys_thread_t:0xef460de0) prio=1
          "Async Garbage Collector" (TID:0xee300368, sys_thread_t:0xef490de0) prio=1
          "Idle thread" (TID:0xee300320, sys_thread_t:0xef4c0de0) prio=0
          "clock handler" (TID:0xee3001f8, sys_thread_t:0xef4f0de0) prio=11
          "main" (TID:0xee3000a0, sys_thread_t:0x812b0) prio=5 *current thread*
      java.lang.UNIXProcess.<init>(UNIXProcess.java:121)
      java.lang.Runtime.exec(Runtime.java)
      java.lang.Runtime.exec(Runtime.java)
      ExecDemo.main(ExecDemo.java:8)
      Monitor Cache Dump:
      Registered Monitor Dump:
          Finalize me queue lock: unowned
          Thread queue lock: unowned
          Class lock: unowned
          Java stack lock: unowned
          Code rewrite lock: unowned
          Heap lock: unowned
          Has finalization queue lock: unowned
          Monitor IO lock: unowned
          Child death monitor: unowned
          Event monitor: unowned
          I/O monitor: unowned
          Alarm monitor: unowned
      Waiting to be notified:
      "clock handler"
          Sbrk lock: unowned
          Monitor cache lock: unowned
          Monitor registry: monitor owner: "main"
      Thread Alarm Q:
      IO Error fd 1: java.io.IOException: read error
      IO Error fd 2: java.io.IOException: read error
      Exit value 6
      coolant{soule}~/javatest>exit

      script done on Tue Jul 02 18:43:54 1996

            djbrown David Brown (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: