Class ProcessStarter
- java.lang.Object
-
- gw.util.ProcessStarter
-
@Deprecated public class ProcessStarter extends java.lang.ObjectDeprecated.useProcessRunnerinstead
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classProcessStarter.GobblerDeprecated.private static classProcessStarter.HandlerWriterDeprecated.static classProcessStarter.NullOutputHandlerDeprecated.static interfaceProcessStarter.OutputHandlerDeprecated.static interfaceProcessStarter.ProcessHandlerDeprecated.private static classProcessStarter.StdErrWriterDeprecated.private static classProcessStarter.StreamPipeDeprecated.
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String_charsetDeprecated.private boolean_dontThrowOnNonZeroReturnDeprecated.private boolean_inludeStdErrInOutputDeprecated.private java.lang.ProcessBuilder_pbDeprecated.private java.lang.String_rawCmdDeprecated.private java.io.Writer_stdErrDeprecated.private java.io.Writer_stdOutDeprecated.private boolean_withCMDDeprecated.private static java.lang.StringCONSOLE_NEWLINEDeprecated.static ProcessStarter.OutputHandlerIGNOREDeprecated.
-
Constructor Summary
Constructors Constructor Description ProcessStarter(java.lang.String command)Deprecated.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description ProcessStarterdoNotThrowOnNonZeroReturnVal()Deprecated.If called, this ProcessStarter will not throw an exception if the underlying process exits with a non-zero return codejava.lang.Stringexec()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.voidexecWithPipe()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.private voidflush(java.io.Writer stdOut)Deprecated.java.io.FilegetDirectory()Deprecated.Returns this process' working directory.java.util.Map<java.lang.String,java.lang.String>getEnvironment()Deprecated.Returns a modifiable string map view of this process' environment.private voidhandleCommand(java.io.Writer stdOut, java.io.Writer stdErr)Deprecated.ProcessStarterincludeStdErrInOutput()Deprecated.If called, this ProcessStarter will include the StdErr output in the return string of this process.private static java.lang.Stringindent(java.lang.String string)Deprecated.private java.util.List<java.lang.String>parseCommandLine(java.lang.String str)Deprecated.voidprocessWithHandler(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.voidsetDirectory(java.io.File directory)Deprecated.Sets this process' working directory.java.lang.Processstart()Deprecated.Starts a new process using the attributes of this process starter.private java.lang.ProcessstartImpl()Deprecated.ProcessStarterwithCharset(java.lang.String cs)Deprecated.ProcessStarterwithCMD()Deprecated.The process built up will use CMD if this is a windows platform.ProcessStarterwithStdErrHandler(ProcessStarter.OutputHandler stdErrHandler)Deprecated.ProcessStarterwithStdOutHandler(ProcessStarter.OutputHandler stdOutHandler)Deprecated.
-
-
-
Field Detail
-
IGNORE
public static final ProcessStarter.OutputHandler IGNORE
Deprecated.
-
CONSOLE_NEWLINE
private static final java.lang.String CONSOLE_NEWLINE
Deprecated.
-
_pb
private final java.lang.ProcessBuilder _pb
Deprecated.
-
_withCMD
private boolean _withCMD
Deprecated.
-
_inludeStdErrInOutput
private boolean _inludeStdErrInOutput
Deprecated.
-
_dontThrowOnNonZeroReturn
private boolean _dontThrowOnNonZeroReturn
Deprecated.
-
_rawCmd
private final java.lang.String _rawCmd
Deprecated.
-
_stdOut
private java.io.Writer _stdOut
Deprecated.
-
_stdErr
private java.io.Writer _stdErr
Deprecated.
-
_charset
private java.lang.String _charset
Deprecated.
-
-
Method Detail
-
parseCommandLine
private java.util.List<java.lang.String> parseCommandLine(java.lang.String str)
Deprecated.
-
exec
public java.lang.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. If the command finishes with a non zero return value, a
CommandFailedExceptionis 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 )
- Returns:
- the content of standard out
- Throws:
CommandFailedException- if the process finishes with a non-zero return value
-
flush
private void flush(java.io.Writer stdOut)
Deprecated.
-
execWithPipe
public 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. If the command finishes with a non zero return value, a
CommandFailedExceptionis 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?\"" )
- Throws:
CommandFailedException- if the process finishes with a non-zero return value
-
startImpl
private java.lang.Process startImpl() throws java.io.IOExceptionDeprecated.- Throws:
java.io.IOException
-
processWithHandler
public 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.
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.
- Parameters:
handler- the process handler for this process.
-
start
public java.lang.Process start() throws java.io.IOExceptionDeprecated.Starts a new process using the attributes of this process starter.The new process will invoke the command and arguments given by
ProcessBuilder.command(), in a working directory as given bygetDirectory(), with a process environment as given bygetEnvironment().This method calls directly to
ProcessBuilder.start.- Returns:
- A new
Processobject for managing the subprocess - Throws:
java.lang.NullPointerException- If an element of the command list is nulljava.lang.IndexOutOfBoundsException- If the command is an empty list (has size0)java.lang.SecurityException- If a security manager exists and itscheckExecmethod doesn't allow creation of the subprocessjava.io.IOException- If an I/O error occurs- See Also:
Runtime.exec(String[], String[], java.io.File),SecurityManager.checkExec(String)
-
getEnvironment
public java.util.Map<java.lang.String,java.lang.String> getEnvironment()
Deprecated.Returns a modifiable string map view of this process' environment. Whenever a process starter is created, the environment is initialized to a copy of the current process environment (seeSystem.getenv()). Subprocesses subsequently started by this object will use this map as their environment.The returned object may be modified using ordinary
Mapoperations. These modifications will be visible to subprocesses. TwoProcessStarterinstances always contain independent process environments, so changes to the returned map will never be reflected in any otherProcessStarterinstance or the values returned bySystem.getenv. There are many system-dependant restrictions placed on the returned map. SeeProcessBuilderfor more information- Returns:
- This process environment
- Throws:
java.lang.SecurityException- If a security manager exists and itscheckPermissionmethod doesn't allow access to the process environment- See Also:
ProcessBuilder,System.getenv()
-
getDirectory
public java.io.File getDirectory()
Deprecated.Returns this process' working directory. Subprocesses subsequently started by this object will use this as their working directory. The returned value may benull-- this means to use the working directory of the current Java process, usually the directory named by the system propertyuser.dir, as the working directory of the child process.- Returns:
- This process's working directory
-
setDirectory
public void setDirectory(java.io.File directory)
Deprecated.Sets this process' working directory. Subprocesses subsequently started by this object will use this as their working directory. The returned value may benull-- this means to use the working directory of the current Java process, usually the directory named by the system propertyuser.dir, as the working directory of the child process.- Parameters:
directory- This process' working directory
-
handleCommand
private void handleCommand(java.io.Writer stdOut, java.io.Writer stdErr)Deprecated.
-
indent
private static java.lang.String indent(java.lang.String string)
Deprecated.
-
withCharset
public ProcessStarter withCharset(java.lang.String cs)
Deprecated.
-
withCMD
public ProcessStarter withCMD()
Deprecated.The process built up will use CMD if this is a windows platform. This is necessary because on windows certain basic commands such as "dir" are not programs, but rather are built into CMD. Thanks, Microsoft.
-
includeStdErrInOutput
public ProcessStarter includeStdErrInOutput()
Deprecated.If called, this ProcessStarter will include the StdErr output in the return string of this process. Note that this has no effect ifwithStdErrHandler(OutputHandler)is called.- Returns:
- this object for chaining
-
doNotThrowOnNonZeroReturnVal
public ProcessStarter doNotThrowOnNonZeroReturnVal()
Deprecated.If called, this ProcessStarter will not throw an exception if the underlying process exits with a non-zero return code- Returns:
- this object for chaining
-
withStdErrHandler
public ProcessStarter withStdErrHandler(ProcessStarter.OutputHandler stdErrHandler)
Deprecated.- Parameters:
stdErrHandler- handler that will be called with every line of output to stderr- Returns:
- this object for chaining
-
withStdOutHandler
public ProcessStarter withStdOutHandler(ProcessStarter.OutputHandler stdOutHandler)
Deprecated.- Parameters:
stdOutHandler- handler that will be called with every line of output to stdout- Returns:
- this object for chaining
-
-