Logo Search packages:      
Sourcecode: jmk version File versions  Download package

void edu::neu::ccs::jmk::ExecOperator::exec ( String[]  args,
PrintWriter  out 
) throws CommandFailedException [inline]

Executes a command in a separate process using the runtime's exec method.

See also:
java.lang.Runtime::exec(String[])
Parameters:
args operands given to exec method of the runtime
out place to write messages
Exceptions:
CommandFailedException if operation failed

Definition at line 54 of file ExecOperator.java.

  {
    String msg = null;        // For error messages
    try {
      // Create the child process.
      Process p = Runtime.getRuntime().exec(args);
      // Start a thread which copies the input stream to out.
      Thread t = new Thread(new BufferedCopy(p.getInputStream(), out));
      t.start();
      // Copy the error stream.
      new BufferedCopy(p.getErrorStream(), out).run();
      int exitCode = p.waitFor(); // Wait for the termination of the child
      t.join();               // Wait for the end of the input stream
      if (exitCode != 0) {
      if (args.length > 0) {  // Copy command when an error occurs
        msg = args[0];
        for (int i = 1; i < args.length; i++)
          msg += " " + args[i];
      }
      else
        msg = "No args to exec";
      }
    }
    catch (IOException ioEx) {      // from exec
      msg = "In exec: " + ioEx.toString();
    }
    catch (InterruptedException iEx) { // from waitFor
      msg = "In waitFor: " + iEx.toString();
    }
    if (msg != null)
      throw new CommandFailedException(msg);
  }


Generated by  Doxygen 1.6.0   Back to index