Class ExecHelper
- Since:
- ostermillerutils 1.06.00
- Author:
- Stephen Ostermiller https://ostermiller.org/contact.pl?regarding=Java+Utilities
-
Method Summary
Modifier and TypeMethodDescriptionstatic ExecHelperExecutes the specified command and arguments in a separate process, and waits for the process to finish.static ExecHelperExecutes the specified command and arguments in a separate process, and waits for the process to finish.static ExecHelperExecutes the specified command and arguments in a separate process, and waits for the process to finish.static ExecHelperExecutes the specified command and arguments in a separate process, and waits for the process to finish.static ExecHelperExecutes the specified command and arguments in a separate process, and waits for the process to finish.static ExecHelperExecutes the specified command and arguments in a separate process, and waits for the process to finish.static ExecHelperexecUsingShell(String command) Executes the specified command using a shell.static ExecHelperexecUsingShell(String command, String charset) Executes the specified command using a shell.getError()Get the error output of the job that ran.Get the output of the job that ran.intGet the status of the job that ran.
-
Method Details
-
exec
Executes the specified command and arguments in a separate process, and waits for the process to finish.Output from the process is expected to be text in the system's default character set.
No input is passed to the process on STDIN.
- Parameters:
cmdarray- array containing the command to call and its arguments.- Returns:
- The results of the execution in an ExecHelper object.
- Throws:
SecurityException- if a security manager exists and its checkExec method doesn't allow creation of a sub process.IOException- - if an I/O error occursNullPointerException- - if cmdarray is nullIndexOutOfBoundsException- - if cmdarray is an empty array (has length 0).- Since:
- ostermillerutils 1.06.00
-
exec
Executes the specified command and arguments in a separate process, and waits for the process to finish.Output from the process is expected to be text in the system's default character set.
No input is passed to the process on STDIN.
- Parameters:
cmdarray- array containing the command to call and its arguments.envp- array of strings, each element of which has environment variable settings in format name=value.- Returns:
- The results of the execution in an ExecHelper object.
- Throws:
SecurityException- if a security manager exists and its checkExec method doesn't allow creation of a sub process.IOException- - if an I/O error occursNullPointerException- - if cmdarray is nullIndexOutOfBoundsException- - if cmdarray is an empty array (has length 0).- Since:
- ostermillerutils 1.06.00
-
exec
Executes the specified command and arguments in a separate process, and waits for the process to finish.Output from the process is expected to be text in the system's default character set.
No input is passed to the process on STDIN.
- Parameters:
cmdarray- array containing the command to call and its arguments.envp- array of strings, each element of which has environment variable settings in format name=value.dir- the working directory of the sub process, or null if the sub process should inherit the working directory of the current process.- Returns:
- The results of the execution in an ExecHelper object.
- Throws:
SecurityException- if a security manager exists and its checkExec method doesn't allow creation of a sub process.IOException- - if an I/O error occursNullPointerException- - if cmdarray is nullIndexOutOfBoundsException- - if cmdarray is an empty array (has length 0).- Since:
- ostermillerutils 1.06.00
-
exec
Executes the specified command and arguments in a separate process, and waits for the process to finish.No input is passed to the process on STDIN.
- Parameters:
cmdarray- array containing the command to call and its arguments.charset- Output from the executed command is expected to be in this character set.- Returns:
- The results of the execution in an ExecHelper object.
- Throws:
SecurityException- if a security manager exists and its checkExec method doesn't allow creation of a sub process.IOException- - if an I/O error occursNullPointerException- - if cmdarray is nullIndexOutOfBoundsException- - if cmdarray is an empty array (has length 0).- Since:
- ostermillerutils 1.06.00
-
exec
Executes the specified command and arguments in a separate process, and waits for the process to finish.No input is passed to the process on STDIN.
- Parameters:
cmdarray- array containing the command to call and its arguments.envp- array of strings, each element of which has environment variable settings in format name=value.charset- Output from the executed command is expected to be in this character set.- Returns:
- The results of the execution in an ExecHelper object.
- Throws:
SecurityException- if a security manager exists and its checkExec method doesn't allow creation of a sub process.IOException- - if an I/O error occursNullPointerException- - if cmdarray is nullIndexOutOfBoundsException- - if cmdarray is an empty array (has length 0).- Since:
- ostermillerutils 1.06.00
-
exec
public static ExecHelper exec(String[] cmdarray, String[] envp, File dir, String charset) throws IOException Executes the specified command and arguments in a separate process, and waits for the process to finish.No input is passed to the process on STDIN.
- Parameters:
cmdarray- array containing the command to call and its arguments.envp- array of strings, each element of which has environment variable settings in format name=value.dir- the working directory of the sub process, or null if the sub process should inherit the working directory of the current process.charset- Output from the executed command is expected to be in this character set.- Returns:
- The results of the execution in an ExecHelper object.
- Throws:
SecurityException- if a security manager exists and its checkExec method doesn't allow creation of a sub process.IOException- - if an I/O error occursNullPointerException- - if cmdarray is nullIndexOutOfBoundsException- - if cmdarray is an empty array (has length 0).- Since:
- ostermillerutils 1.06.00
-
execUsingShell
Executes the specified command using a shell. On windows uses cmd.exe or command.exe. On other platforms it uses /bin/sh.A shell should be used to execute commands when features such as file redirection, pipes, argument parsing are desired.
Output from the process is expected to be text in the system's default character set.
No input is passed to the process on STDIN.
- Parameters:
command- String containing a command to be parsed by the shell and executed.- Returns:
- The results of the execution in an ExecHelper object.
- Throws:
SecurityException- if a security manager exists and its checkExec method doesn't allow creation of a sub process.IOException- - if an I/O error occursNullPointerException- - if command is null- Since:
- ostermillerutils 1.06.00
-
execUsingShell
Executes the specified command using a shell. On windows uses cmd.exe or command.exe. On other platforms it uses /bin/sh.A shell should be used to execute commands when features such as file redirection, pipes, argument parsing are desired.
No input is passed to the process on STDIN.
- Parameters:
command- String containing a command to be parsed by the shell and executed.charset- Output from the executed command is expected to be in this character set.- Returns:
- The results of the execution in an ExecHelper object.
- Throws:
SecurityException- if a security manager exists and its checkExec method doesn't allow creation of a sub process.IOException- - if an I/O error occursNullPointerException- - if command is null- Since:
- ostermillerutils 1.06.00
-
getOutput
Get the output of the job that ran.- Returns:
- Everything the executed process wrote to its standard output as a String.
- Since:
- ostermillerutils 1.06.00
-
getError
Get the error output of the job that ran.- Returns:
- Everything the executed process wrote to its standard error as a String.
- Since:
- ostermillerutils 1.06.00
-
getStatus
public int getStatus()Get the status of the job that ran.- Returns:
- exit status of the executed process, by convention, the value 0 indicates normal termination.
- Since:
- ostermillerutils 1.06.00
-