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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Execed
Runs a command, optionally executing as a different user (eg root)static Execed
Runs a command, optionally executing as a different user (eg root)customiseProcessBuilder
(Consumer<ProcessBuilder> customiser) Apply customisations to the internalProcessBuilder
Returns a ProcessBuilder for use in a manual launchingboolean
protected static String
protected static String
static Execed
rootUtility
(Iterable<String> command) Runs a command in "utility" mode: redirecting stderr to stdout and running as rootstatic Execed
rootUtility
(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 Execed
Runs a command in "utility" mode: redirecting stderr to stdout and optionally executing as a different user (eg root)static Execed
Runs a command in "utility" mode: redirecting stderr to stdout and optionally executing as a different user (eg root)static Execed
Runs a command in "utility" mode: redirecting stderr to stdout and optionally executing as a different user (eg root)static Execed
Runs 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
-