Shell.ShellCommandExecutor
public abstract class Shell
extends java.lang.Object
Shell
can be used to run unix commands like du
or
df
. It also offers facilities to gate commands by
time-intervals.Modifier and Type | Class | Description |
---|---|---|
static class |
Shell.ExitCodeException |
This is an IOException with exit code added.
|
static class |
Shell.ShellCommandExecutor |
A simple shell command executor.
|
Modifier and Type | Field | Description |
---|---|---|
static java.lang.String |
SET_GROUP_COMMAND |
|
static java.lang.String |
SET_OWNER_COMMAND |
a Unix command to set owner
|
static java.lang.String |
SET_PERMISSION_COMMAND |
a Unix command to set permission
|
static java.lang.String |
ULIMIT_COMMAND |
a Unix command to get ulimit of a process.
|
static java.lang.String |
USER_NAME_COMMAND |
a Unix command to get the current user's name
|
static boolean |
WINDOWS |
Set to true on Windows platforms
|
Modifier and Type | Method | Description |
---|---|---|
static java.lang.String |
execCommand(java.lang.String... cmd) |
Static method to execute a shell command.
|
static java.lang.String |
execCommand(java.util.Map<java.lang.String,java.lang.String> env,
java.lang.String... cmd) |
Static method to execute a shell command.
|
static java.lang.String |
execCommand(java.util.Map<java.lang.String,java.lang.String> env,
java.lang.String[] cmd,
long timeout) |
Static method to execute a shell command.
|
int |
getExitCode() |
get the exit code
|
static java.lang.String[] |
getGET_PERMISSION_COMMAND() |
Return a Unix command to get permission information.
|
static java.lang.String[] |
getGroupsCommand() |
a Unix command to get the current user's groups list
|
static java.lang.String[] |
getGroupsForUserCommand(java.lang.String user) |
a Unix command to get a given user's groups list
|
java.lang.Process |
getProcess() |
get the current sub-process executing the given command
|
static java.lang.String[] |
getUlimitMemoryCommand(int memoryLimit) |
Get the Unix command for setting the maximum virtual memory available
to a given child process.
|
boolean |
isTimedOut() |
To check if the passed script to shell command executor timed out or
not.
|
public static final java.lang.String USER_NAME_COMMAND
public static final java.lang.String SET_PERMISSION_COMMAND
public static final java.lang.String SET_OWNER_COMMAND
public static final java.lang.String SET_GROUP_COMMAND
public static final java.lang.String ULIMIT_COMMAND
public static final boolean WINDOWS
public Shell()
public Shell(long interval)
interval
- the minimum duration to wait before re-executing the
command.public static java.lang.String[] getGroupsCommand()
public static java.lang.String[] getGroupsForUserCommand(java.lang.String user)
public static java.lang.String[] getGET_PERMISSION_COMMAND()
public static java.lang.String[] getUlimitMemoryCommand(int memoryLimit)
null
.memoryLimit
- virtual memory limitString[]
with the ulimit command arguments or
null
if we are running on a non *nix platform or
if the limit is unspecified.public java.lang.Process getProcess()
public int getExitCode()
public boolean isTimedOut()
public static java.lang.String execCommand(java.lang.String... cmd) throws java.io.IOException
Shell
interface.cmd
- shell command to execute.java.io.IOException
public static java.lang.String execCommand(java.util.Map<java.lang.String,java.lang.String> env, java.lang.String[] cmd, long timeout) throws java.io.IOException
Shell
interface.env
- the map of environment key=valuecmd
- shell command to execute.timeout
- time in milliseconds after which script should be marked timeoutjava.io.IOException
public static java.lang.String execCommand(java.util.Map<java.lang.String,java.lang.String> env, java.lang.String... cmd) throws java.io.IOException
Shell
interface.env
- the map of environment key=valuecmd
- shell command to execute.java.io.IOException
Copyright © 2018 The Apache Software Foundation