ProcessRunner instead@Deprecated public class ProcessStarter extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
ProcessStarter.NullOutputHandler
Deprecated.
|
static interface |
ProcessStarter.OutputHandler
Deprecated.
|
static interface |
ProcessStarter.ProcessHandler
Deprecated.
|
| Modifier and Type | Field and Description |
|---|---|
static ProcessStarter.OutputHandler |
IGNORE
Deprecated.
|
| Constructor and Description |
|---|
ProcessStarter(String command)
Deprecated.
|
| Modifier and Type | Method and Description |
|---|---|
ProcessStarter |
doNotThrowOnNonZeroReturnVal()
Deprecated.
If called, this ProcessStarter will not throw an exception if the underlying process exits with
a non-zero return code
|
String |
exec()
Deprecated.
Executes the given command as if it had been executed from the command line of the host OS
(cmd.exe on windows, /bin/sh on *nix) and returns all content sent to standard out as a string.
|
void |
execWithPipe()
Deprecated.
Executes the given command as if it had been executed from the command line of the host OS
(cmd.exe on windows, /bin/sh on *nix) and pipes all data sent to this processes stdout, stderr, and stdin.
|
File |
getDirectory()
Deprecated.
Returns this process' working directory.
|
Map<String,String> |
getEnvironment()
Deprecated.
Returns a modifiable string map view of this process' environment.
|
ProcessStarter |
includeStdErrInOutput()
Deprecated.
If called, this ProcessStarter will include the StdErr output in the return string of this
process.
|
void |
processWithHandler(ProcessStarter.ProcessHandler handler)
Deprecated.
Executes the given command as if it had been executed from the command line of the host OS
(cmd.exe on windows, /bin/sh on *nix) and calls the provided handler with the newly created process.
|
void |
setDirectory(File directory)
Deprecated.
Sets this process' working directory.
|
Process |
start()
Deprecated.
Starts a new process using the attributes of this process starter.
|
ProcessStarter |
withCharset(String cs)
Deprecated.
|
ProcessStarter |
withCMD()
Deprecated.
The process built up will use CMD if this is a windows platform.
|
ProcessStarter |
withStdErrHandler(ProcessStarter.OutputHandler stdErrHandler)
Deprecated.
|
ProcessStarter |
withStdOutHandler(ProcessStarter.OutputHandler stdOutHandler)
Deprecated.
|
public static final ProcessStarter.OutputHandler IGNORE
public ProcessStarter(String command)
public String exec()
Executes the given command as if it had been executed from the command line of the host OS
(cmd.exe on windows, /bin/sh on *nix) and returns all content sent to standard out as a string. If the command
finishes with a non zero return value, a CommandFailedException is thrown.
Content sent to standard error by the command will be forwarded to standard error for this JVM.
This method blocks on the execution of the command.
Example Usages:
var currentDir = Shell.exec( "dir" ) // windows var currentDir = Shell.exec( "ls" ) // *nix Shell.exec( "rm -rf " + directoryToNuke )
CommandFailedException - if the process finishes with a non-zero return valuepublic void execWithPipe()
Executes the given command as if it had been executed from the command line of the host OS
(cmd.exe on windows, /bin/sh on *nix) and pipes all data sent to this processes stdout, stderr, and stdin. If the command
finishes with a non zero return value, a CommandFailedException is thrown.
Stdout and Stderr from the sub-process will be piped to the current process' stdout and stderr. Any input in this processes stdin will be piped to the sub-process' stdin
Content sent to standard error by the command will be forwarded to standard error for this JVM.
This method blocks on the execution of the command.
Example Usages:
Shell.execWithPipe( "read \"are you there?\"" )
CommandFailedException - if the process finishes with a non-zero return valuepublic void processWithHandler(ProcessStarter.ProcessHandler handler)
Executes the given command as if it had been executed from the command line of the host OS (cmd.exe on windows, /bin/sh on *nix) and calls the provided handler with the newly created process.
NOTE: In gosu, you should take advantage of the block-to-interface coercion provided and pass blocks in as the handler. See the examples below.
handler - the process handler for this process.public Process start() throws IOException
The new process will
invoke the command and arguments given by ProcessBuilder.command(),
in a working directory as given by getDirectory(),
with a process environment as given by getEnvironment().
This method calls directly to ProcessBuilder.start.
Process object for managing the subprocessNullPointerException - If an element of the command list is nullIndexOutOfBoundsException - If the command is an empty list (has size 0)SecurityException - If a security manager exists and its
checkExec
method doesn't allow creation of the subprocessIOException - If an I/O error occursRuntime.exec(String[], String[], java.io.File),
SecurityManager.checkExec(String)public Map<String,String> getEnvironment()
System.getenv()). Subprocesses subsequently started by
this object will use this map as their environment.
The returned object may be modified using ordinary Map operations. These modifications will be
visible to subprocesses. Two ProcessStarter instances always
contain independent process environments, so changes to the
returned map will never be reflected in any other
ProcessStarter instance or the values returned by
System.getenv.
There are many system-dependant restrictions placed on the returned map.
See ProcessBuilder for more information
SecurityException - If a security manager exists and its
checkPermission
method doesn't allow access to the process environmentProcessBuilder,
System.getenv()public File getDirectory()
null -- this means to use
the working directory of the current Java process, usually the
directory named by the system property user.dir,
as the working directory of the child process.public void setDirectory(File directory)
null -- this means to use
the working directory of the current Java process, usually the
directory named by the system property user.dir,
as the working directory of the child process.directory - This process' working directorypublic ProcessStarter withCharset(String cs)
public ProcessStarter withCMD()
public ProcessStarter includeStdErrInOutput()
withStdErrHandler(OutputHandler) is called.public ProcessStarter doNotThrowOnNonZeroReturnVal()
public ProcessStarter withStdErrHandler(ProcessStarter.OutputHandler stdErrHandler)
stdErrHandler - handler that will be called with every line of output to stderrpublic ProcessStarter withStdOutHandler(ProcessStarter.OutputHandler stdOutHandler)
stdOutHandler - handler that will be called with every line of output to stdoutCopyright © 2018. All rights reserved.