public abstract class CommandLineUtils extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
CommandLineUtils.StringStreamConsumer |
| Constructor and Description |
|---|
CommandLineUtils() |
| Modifier and Type | Method and Description |
|---|---|
static int |
executeCommandLine(Commandline cl,
InputStream systemIn,
StreamConsumer systemOut,
StreamConsumer systemErr) |
static int |
executeCommandLine(Commandline cl,
InputStream systemIn,
StreamConsumer systemOut,
StreamConsumer systemErr,
int timeoutInSeconds) |
static int |
executeCommandLine(Commandline cl,
InputStream systemIn,
StreamConsumer systemOut,
StreamConsumer systemErr,
int timeoutInSeconds,
Runnable runAfterProcessTermination) |
static int |
executeCommandLine(Commandline cl,
InputStream systemIn,
StreamConsumer systemOut,
StreamConsumer systemErr,
int timeoutInSeconds,
Runnable runAfterProcessTermination,
Charset streamCharset) |
static int |
executeCommandLine(Commandline cl,
StreamConsumer systemOut,
StreamConsumer systemErr) |
static int |
executeCommandLine(Commandline cl,
StreamConsumer systemOut,
StreamConsumer systemErr,
int timeoutInSeconds) |
static CommandLineCallable |
executeCommandLineAsCallable(Commandline cl,
InputStream systemIn,
StreamConsumer systemOut,
StreamConsumer systemErr,
int timeoutInSeconds,
Runnable runAfterProcessTermination)
Immediately forks a process, returns a callable that will block until process is complete.
|
static CommandLineCallable |
executeCommandLineAsCallable(Commandline cl,
InputStream systemIn,
StreamConsumer systemOut,
StreamConsumer systemErr,
int timeoutInSeconds,
Runnable runAfterProcessTermination,
Charset streamCharset)
Immediately forks a process, returns a callable that will block until process is complete.
|
static Properties |
getSystemEnvVars()
Gets the shell environment variables for this process.
|
static Properties |
getSystemEnvVars(boolean caseSensitive)
Return the shell environment variables.
|
static String |
toString(String... line) |
static String[] |
translateCommandline(String toProcess) |
public static int executeCommandLine(@Nonnull Commandline cl, StreamConsumer systemOut, StreamConsumer systemErr) throws CommandLineException
cl - The command line CommandlinesystemOut - StreamConsumersystemErr - StreamConsumerCommandLineException - in case of a problem.public static int executeCommandLine(@Nonnull Commandline cl, StreamConsumer systemOut, StreamConsumer systemErr, int timeoutInSeconds) throws CommandLineException
cl - The command line CommandlinesystemOut - StreamConsumersystemErr - StreamConsumertimeoutInSeconds - The timeout.CommandLineException - in case of a problem.public static int executeCommandLine(@Nonnull Commandline cl, InputStream systemIn, StreamConsumer systemOut, StreamConsumer systemErr) throws CommandLineException
cl - The command line CommandlinesystemIn - StreamConsumersystemOut - StreamConsumersystemErr - StreamConsumerCommandLineException - in case of a problem.public static int executeCommandLine(@Nonnull Commandline cl, InputStream systemIn, StreamConsumer systemOut, StreamConsumer systemErr, int timeoutInSeconds) throws CommandLineException
cl - The command line to executesystemIn - The input to read from, must be thread safesystemOut - A consumer that receives output, must be thread safesystemErr - A consumer that receives system error stream output, must be thread safetimeoutInSeconds - Positive integer to specify timeout, zero and negative integers for no timeout.Process.exitValue()CommandLineException - or CommandLineTimeOutException if time out occurspublic static int executeCommandLine(@Nonnull Commandline cl, InputStream systemIn, StreamConsumer systemOut, StreamConsumer systemErr, int timeoutInSeconds, @Nullable Runnable runAfterProcessTermination) throws CommandLineException
cl - The command line to executesystemIn - The input to read from, must be thread safesystemOut - A consumer that receives output, must be thread safesystemErr - A consumer that receives system error stream output, must be thread safetimeoutInSeconds - Positive integer to specify timeout, zero and negative integers for no timeout.runAfterProcessTermination - Optional callback to run after the process terminated or the the timeout was
exceeded, but before waiting on the stream feeder and pumpers to finish.Process.exitValue()CommandLineException - or CommandLineTimeOutException if time out occurspublic static int executeCommandLine(@Nonnull Commandline cl, InputStream systemIn, StreamConsumer systemOut, StreamConsumer systemErr, int timeoutInSeconds, @Nullable Runnable runAfterProcessTermination, @Nullable Charset streamCharset) throws CommandLineException
cl - The command line to executesystemIn - The input to read from, must be thread safesystemOut - A consumer that receives output, must be thread safesystemErr - A consumer that receives system error stream output, must be thread safetimeoutInSeconds - Positive integer to specify timeout, zero and negative integers for no timeout.runAfterProcessTermination - Optional callback to run after the process terminated or the the timeout was
exceeded, but before waiting on the stream feeder and pumpers to finish.streamCharset - Charset to use for reading streamsProcess.exitValue()CommandLineException - or CommandLineTimeOutException if time out occurspublic static CommandLineCallable executeCommandLineAsCallable(@Nonnull Commandline cl, @Nullable InputStream systemIn, StreamConsumer systemOut, StreamConsumer systemErr, int timeoutInSeconds, @Nullable Runnable runAfterProcessTermination) throws CommandLineException
cl - The command line to executesystemIn - The input to read from, must be thread safesystemOut - A consumer that receives output, must be thread safesystemErr - A consumer that receives system error stream output, must be thread safetimeoutInSeconds - Positive integer to specify timeout, zero and negative integers for no timeout.runAfterProcessTermination - Optional callback to run after the process terminated or the the timeout wasProcess.exitValue(). "call"
must be called on this to be sure the forked process has terminated, no guarantees is made about
any internal state before after the completion of the call statementsCommandLineException - or CommandLineTimeOutException if time out occurspublic static CommandLineCallable executeCommandLineAsCallable(@Nonnull Commandline cl, @Nullable InputStream systemIn, StreamConsumer systemOut, StreamConsumer systemErr, int timeoutInSeconds, @Nullable Runnable runAfterProcessTermination, @Nullable Charset streamCharset) throws CommandLineException
cl - The command line to executesystemIn - The input to read from, must be thread safesystemOut - A consumer that receives output, must be thread safesystemErr - A consumer that receives system error stream output, must be thread safetimeoutInSeconds - Positive integer to specify timeout, zero and negative integers for no timeout.runAfterProcessTermination - Optional callback to run after the process terminated or the the timeout wasstreamCharset - Charset to use for reading streamsProcess.exitValue(). "call"
must be called on this to be sure the forked process has terminated, no guarantees is made about
any internal state before after the completion of the call statementsCommandLineException - or CommandLineTimeOutException if time out occurspublic static Properties getSystemEnvVars()
getSystemEnvVars().get("path")
and getSystemEnvVars().get("PATH") will in general return different values. However, on platforms
with case-insensitive environment variables like Windows, all variable names will be normalized to upper case.null.System.getenv() API, new in JDK 5.0, to get the same result
since 2.0.2 System#getenv() will be used if available in the current running jvm.public static Properties getSystemEnvVars(boolean caseSensitive)
caseSensitive == true, then envar
keys will all be upper-case.caseSensitive - Whether environment variable keys should be treated case-sensitively.System.getenv() API, new in JDK 5.0, to get the same result
since 2.0.2 System#getenv() will be used if available in the current running jvm.public static String[] translateCommandline(String toProcess) throws CommandLineException
toProcess - The command line to translate.CommandLineException - in case of unbalanced quotes.Copyright © 2002–2016 The Apache Software Foundation. All rights reserved.