Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.sun.javatest.lib
Class ProcessCommand

    java.lang.Object
      com.sun.javatest.Command
          com.sun.javatest.lib.ProcessCommand

Direct Known Subclasses:
  ExecStdTestOtherJVMCmd

    public class ProcessCommand

extends Command

A Command to execute an arbitrary OS command.

Constructor Summary
`ProcessCommand()`

Method Summary
`Status` | `exec(java.lang.String[] cmd, java.lang.String[] cmdEnv, java.io.PrintWriter log, java.io.PrintWriter ref)` Execute a command, bypassing the standard argument decoding of 'run'.
`java.io.File` | `getExecDir()` Get the directory in which to execute the process, or null if none set.
`protected Status` | `getStatus(int exitCode, Status logStatus)` Generate a status for the command, based upon the command's exit code and a status that may have been passed from the command by using `status.exit()`.
`static void` | `main(java.lang.String[] args)` A stand-alone entry point for this command.
`Status` | `run(java.lang.String[] args, java.io.PrintWriter log, java.io.PrintWriter ref)` Run the given command.
`void` | `setDefaultStatus(Status status)` Set the default status to be returned for all exit codes.
`void` | `setExecDir(java.io.File dir)` Set the directory in which to execute the process.
`void` | `setStatusForExit(int exitCode, Status status)` Set a status to be returned for a specific exit code, overwriting any previous setting for this exit code.

Methods inherited from class com.sun.javatest.Command
`getClassLoader, setClassLoader`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### ProcessCommand

    public ProcessCommand()

Method Detail

### main

    public static void main(java.lang.String[] args)

  A stand-alone entry point for this command. An instance of this command is created, and its `run` method invoked, passing in the command line args and `System.out` and `System.err` as the two streams.

  Parameters:
    `args` - command line arguments for this command.
  See Also:
    `run(java.lang.String[], java.io.PrintWriter, java.io.PrintWriter)`

### setStatusForExit

    public void setStatusForExit(int exitCode,
                                 Status status)

  Set a status to be returned for a specific exit code, overwriting any previous setting for this exit code. If the default status has not yet been initialized, it is set to Status.error("unrecognized exit code").

  Parameters:
    `exitCode` - The process exit code for which to assign a status.
    `status` - The status to associate with the exit code.

### setDefaultStatus

    public void setDefaultStatus(Status status)

  Set the default status to be returned for all exit codes. This will not affect any values for specific exit codes that may have been set with setStatusForExit. If this method is not called, the default value will be Status.failed (for backwards compatibility) unless setStatusForExit has been called, which sets the default value to Status.error.

  Parameters:
    `status` - The default status to use when a specific status has not been set for a particular process exit code.

### setExecDir

    public void setExecDir(java.io.File dir)

  Set the directory in which to execute the process. Use null to indicate the default directory.

  Parameters:
    `dir` - the directory in which to execute the process.
  See Also:
    `getExecDir()`

### getExecDir

    public java.io.File getExecDir()

  Get the directory in which to execute the process, or null if none set.

  Returns:
    the directory in which to execute the process.
  See Also:
    `setExecDir(java.io.File)`

### run

    public Status run(java.lang.String[] args,
                      java.io.PrintWriter log,
                      java.io.PrintWriter ref)

  Run the given command.

  Specified by:
    `run` in class `Command`
  Parameters:
    `args` - An array of strings composed of command-options, environment-variables, command, command-arguments.
    The command-options are an optional set of options, each beginning with `-', to be used by this object. The options are
  -v
    verbose mode
  -pass|-fail|-error exit-code string
    set the status to be returned for the given exit code to one of Status.passed/Status.failed/Status.error. exit-code can be either an integer or "default". string the message string provided in the status object.
  -execDir execDir
    set the directory in which to execute the command.
  -inheritEnv
    Instructs the code which invokes the new process to allow it to inherit the parent environment values.
  The environment-variables are an optional list of environment variable to be supplied to the command. They should be in the form NAME`=`VALUE.
  The command identifies the command to be executed. This name will be platform specific.
  The command-arguments are an optional list of strings to be passed to the command to be executed.
  `log` - A stream for logging output.
  `ref` - A stream for reference output, if the test requires it. If not, it can be used as an additional logging stream.
Returns:
  The result of the method is obtained by calling `getStatus` after the command completes. The default behaviour is to use the explicit or default status given in the arguments, or via the API. If none have been set up, then the following values are used: `Status.passed("exit code 0")` if the command exited with exit status 0, or `Status.failed("exit code " + exitCode)` otherwise. `getStatus` may be overridden to provide different behavior.
See Also:
  `getStatus(int, com.sun.javatest.Status)`

### exec

    public Status exec(java.lang.String[] cmd,
                       java.lang.String[] cmdEnv,
                       java.io.PrintWriter log,
                       java.io.PrintWriter ref)

  Execute a command, bypassing the standard argument decoding of 'run'.

  Parameters:
    `cmd` - The command to be executed
    `cmdEnv` - The environment to be passed to the command
    `log` - A stream for logging output.
    `ref` - A stream for reference output, if the test requires it. If not, it can be used as an additional logging stream.
  Returns:
    The result of the method is obtained by calling `getStatus` after the command completes.
  See Also:
    `run(java.lang.String[], java.io.PrintWriter, java.io.PrintWriter)`, `getStatus(int, com.sun.javatest.Status)`

### getStatus

    protected Status getStatus(int exitCode,
                               Status logStatus)

  Generate a status for the command, based upon the command's exit code and a status that may have been passed from the command by using `status.exit()`.

  Parameters:
    `exitCode` - The exit code from the command that was executed.
    `logStatus` - If the command that was executed was a test program and exited by calling `status.exit()`, then logStatus will be set to `status'. Otherwise, it will be null. The value of the status is passed from the command by writing it as the last line to stdout before exiting the process. If it is not received as the last line, the value will be lost.
  Returns:
    Unless overridden, the default is `Status.passed("exit code 0")` if the command exited with exit code 0, or `Status.failed("exit code " + exitCode)` otherwise.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.