public final class ExecHelper
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static ExecHelper |
exec(java.lang.String[] cmdarray)
Executes the specified command and arguments in a separate process, and waits for the
process to finish.
|
static ExecHelper |
exec(java.lang.String[] cmdarray,
java.lang.String charset)
Executes the specified command and arguments in a separate process, and waits for the
process to finish.
|
static ExecHelper |
exec(java.lang.String[] cmdarray,
java.lang.String[] envp)
Executes the specified command and arguments in a separate process, and waits for the
process to finish.
|
static ExecHelper |
exec(java.lang.String[] cmdarray,
java.lang.String[] envp,
java.io.File dir)
Executes the specified command and arguments in a separate process, and waits for the
process to finish.
|
static ExecHelper |
exec(java.lang.String[] cmdarray,
java.lang.String[] envp,
java.io.File dir,
java.lang.String charset)
Executes the specified command and arguments in a separate process, and waits for the
process to finish.
|
static ExecHelper |
exec(java.lang.String[] cmdarray,
java.lang.String[] envp,
java.lang.String charset)
Executes the specified command and arguments in a separate process, and waits for the
process to finish.
|
static ExecHelper |
execUsingShell(java.lang.String command)
Executes the specified command using a shell.
|
static ExecHelper |
execUsingShell(java.lang.String command,
java.lang.String charset)
Executes the specified command using a shell.
|
java.lang.String |
getError()
Get the error output of the job that ran.
|
java.lang.String |
getOutput()
Get the output of the job that ran.
|
int |
getStatus()
Get the status of the job that ran.
|
public static ExecHelper exec(java.lang.String[] cmdarray) throws java.io.IOException
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.
cmdarray
- array containing the command to call and its arguments.java.lang.SecurityException
- if a security manager exists and its checkExec method doesn't allow creation of a subprocess.java.io.IOException
- - if an I/O error occursjava.lang.NullPointerException
- - if cmdarray is nulljava.lang.IndexOutOfBoundsException
- - if cmdarray is an empty array (has length 0).public static ExecHelper exec(java.lang.String[] cmdarray, java.lang.String[] envp) throws java.io.IOException
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.
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.java.lang.SecurityException
- if a security manager exists and its checkExec method doesn't allow creation of a subprocess.java.io.IOException
- - if an I/O error occursjava.lang.NullPointerException
- - if cmdarray is nulljava.lang.IndexOutOfBoundsException
- - if cmdarray is an empty array (has length 0).public static ExecHelper exec(java.lang.String[] cmdarray, java.lang.String[] envp, java.io.File dir) throws java.io.IOException
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.
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 subprocess, or null if the subprocess should inherit the working directory of the current process.java.lang.SecurityException
- if a security manager exists and its checkExec method doesn't allow creation of a subprocess.java.io.IOException
- - if an I/O error occursjava.lang.NullPointerException
- - if cmdarray is nulljava.lang.IndexOutOfBoundsException
- - if cmdarray is an empty array (has length 0).public static ExecHelper exec(java.lang.String[] cmdarray, java.lang.String charset) throws java.io.IOException
No input is passed to the process on STDIN.
cmdarray
- array containing the command to call and its arguments.charset
- Output from the executed command is expected to be in this character set.java.lang.SecurityException
- if a security manager exists and its checkExec method doesn't allow creation of a subprocess.java.io.IOException
- - if an I/O error occursjava.lang.NullPointerException
- - if cmdarray is nulljava.lang.IndexOutOfBoundsException
- - if cmdarray is an empty array (has length 0).public static ExecHelper exec(java.lang.String[] cmdarray, java.lang.String[] envp, java.lang.String charset) throws java.io.IOException
No input is passed to the process on STDIN.
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.java.lang.SecurityException
- if a security manager exists and its checkExec method doesn't allow creation of a subprocess.java.io.IOException
- - if an I/O error occursjava.lang.NullPointerException
- - if cmdarray is nulljava.lang.IndexOutOfBoundsException
- - if cmdarray is an empty array (has length 0).public static ExecHelper exec(java.lang.String[] cmdarray, java.lang.String[] envp, java.io.File dir, java.lang.String charset) throws java.io.IOException
No input is passed to the process on STDIN.
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 subprocess, or null if the subprocess should inherit the working directory of the current process.charset
- Output from the executed command is expected to be in this character set.java.lang.SecurityException
- if a security manager exists and its checkExec method doesn't allow creation of a subprocess.java.io.IOException
- - if an I/O error occursjava.lang.NullPointerException
- - if cmdarray is nulljava.lang.IndexOutOfBoundsException
- - if cmdarray is an empty array (has length 0).public static ExecHelper execUsingShell(java.lang.String command) throws java.io.IOException
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.
command
- String containing a command to be parsed by the shell and executed.java.lang.SecurityException
- if a security manager exists and its checkExec method doesn't allow creation of a subprocess.java.io.IOException
- - if an I/O error occursjava.lang.NullPointerException
- - if command is nullpublic static ExecHelper execUsingShell(java.lang.String command, java.lang.String charset) throws java.io.IOException
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.
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.java.lang.SecurityException
- if a security manager exists and its checkExec method doesn't allow creation of a subprocess.java.io.IOException
- - if an I/O error occursjava.lang.NullPointerException
- - if command is nullpublic java.lang.String getOutput()
public java.lang.String getError()
public int getStatus()
Copyright (c) 2001-2020 by Stephen Ostermiller