Package com.peterphi.std.system.exec
Class Exec
java.lang.Object
com.peterphi.std.system.exec.Exec
An abstraction over ProcessBuilder to simplify the creation of processes
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ExecedRuns a command, optionally executing as a different user (eg root)static ExecedRuns a command, optionally executing as a different user (eg root)customiseProcessBuilder(Consumer<ProcessBuilder> customiser) Apply customisations to the internalProcessBuilderReturns a ProcessBuilder for use in a manual launchingbooleanprotected static Stringprotected static Stringstatic ExecedrootUtility(Iterable<String> command) Runs a command in "utility" mode: redirecting stderr to stdout and running as rootstatic ExecedrootUtility(String... command) Runs a command in "utility" mode: redirecting stderr to stdout and running as rootsetRedirectError(boolean value) setRedirectError(File file) setRedirectOutput(File file) setWorkingDirectory(File dir) start()Launches the process, returning a handle to it for IO ops, etc.
The finish condition for the OutputProcess is that all processes outputting to standard out must be complete before proceedingLaunches the process, returning a handle to it for IO ops, etc
the caller must read the output streams: otherwise the buffers may fill up and the remote program will be suspended indefinitelystatic ExecedRuns a command in "utility" mode: redirecting stderr to stdout and optionally executing as a different user (eg root)static ExecedRuns a command in "utility" mode: redirecting stderr to stdout and optionally executing as a different user (eg root)static ExecedRuns a command in "utility" mode: redirecting stderr to stdout and optionally executing as a different user (eg root)static ExecedRuns a command in "utility" mode: redirecting stderr to stdout and optionally executing as a different user (eg root)
-
Field Details
-
cmd
-
-
Constructor Details
-
Exec
-
Exec
-
-
Method Details
-
customiseProcessBuilder
Apply customisations to the internalProcessBuilder- Parameters:
customiser- custom logic to run- Returns:
- this
-
getWorkingDirectory
-
setWorkingDirectory
-
setEnv
-
getEnv
-
runAsSuperuser
-
runAs
-
getRedirectError
public boolean getRedirectError() -
setRedirectError
-
setRedirectError
-
setRedirectOutput
-
startBasic
Launches the process, returning a handle to it for IO ops, etc
the caller must read the output streams: otherwise the buffers may fill up and the remote program will be suspended indefinitely- Returns:
- Throws:
IOException
-
start
Launches the process, returning a handle to it for IO ops, etc.
The finish condition for the OutputProcess is that all processes outputting to standard out must be complete before proceeding- Returns:
- Throws:
IOException
-
getProcessBuilder
Returns a ProcessBuilder for use in a manual launching- Returns:
-
join
-
join
-
rootUtility
Runs a command in "utility" mode: redirecting stderr to stdout and running as root- Parameters:
command-- Returns:
- Throws:
IOException
-
rootUtility
Runs a command in "utility" mode: redirecting stderr to stdout and running as root- Parameters:
command-- Returns:
- Throws:
IOException
-
utility
Runs a command in "utility" mode: redirecting stderr to stdout and optionally executing as a different user (eg root)- Parameters:
command-- Returns:
- Throws:
IOException
-
utility
Runs a command in "utility" mode: redirecting stderr to stdout and optionally executing as a different user (eg root)- Parameters:
command-- Returns:
- Throws:
IOException
-
utilityAs
Runs a command in "utility" mode: redirecting stderr to stdout and optionally executing as a different user (eg root)- Parameters:
as-command-- Returns:
- Throws:
IOException
-
utilityAs
Runs a command in "utility" mode: redirecting stderr to stdout and optionally executing as a different user (eg root)- Parameters:
as-command-- Returns:
- Throws:
IOException
-
appAs
Runs a command, optionally executing as a different user (eg root)- Parameters:
as-command-- Returns:
- Throws:
IOException
-
appAs
Runs a command, optionally executing as a different user (eg root)- Parameters:
as-command-- Returns:
- Throws:
IOException
-