Package org.codehaus.plexus.util.cli
Class CommandLineUtils
java.lang.Object
org.codehaus.plexus.util.cli.CommandLineUtils
- Version:
- $Id$
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
AStreamConsumer
providing consumed lines as aString
. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final long
Number of milliseconds per second.private static final long
Number of nanoseconds per second. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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, 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) Immediately forks a process, returns a callable that will block until process is complete.static Properties
Gets the shell environment variables for this process.static Properties
getSystemEnvVars
(boolean caseSensitive) Return the shell environment variables.private static void
handleException
(StreamFeeder streamFeeder, String streamName) private static void
handleException
(StreamPumper streamPumper, String streamName) static boolean
static String
Deprecated.static String
static String
quote
(String argument, boolean escapeSingleQuotes, boolean escapeDoubleQuotes, boolean wrapExistingQuotes) static String
static String[]
translateCommandline
(String toProcess)
-
Field Details
-
MILLIS_PER_SECOND
private static final long MILLIS_PER_SECONDNumber of milliseconds per second.- See Also:
-
NANOS_PER_SECOND
private static final long NANOS_PER_SECONDNumber of nanoseconds per second.- See Also:
-
-
Constructor Details
-
CommandLineUtils
public CommandLineUtils()
-
-
Method Details
-
executeCommandLine
public static int executeCommandLine(Commandline cl, StreamConsumer systemOut, StreamConsumer systemErr) throws CommandLineException - Throws:
CommandLineException
-
executeCommandLine
public static int executeCommandLine(Commandline cl, StreamConsumer systemOut, StreamConsumer systemErr, int timeoutInSeconds) throws CommandLineException - Throws:
CommandLineException
-
executeCommandLine
public static int executeCommandLine(Commandline cl, InputStream systemIn, StreamConsumer systemOut, StreamConsumer systemErr) throws CommandLineException - Throws:
CommandLineException
-
executeCommandLine
public static int executeCommandLine(Commandline cl, InputStream systemIn, StreamConsumer systemOut, StreamConsumer systemErr, int timeoutInSeconds) throws CommandLineException - Parameters:
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.- Returns:
- A return value, see
Process.exitValue()
- Throws:
CommandLineException
- or CommandLineTimeOutException if time out occurs
-
executeCommandLineAsCallable
public static CommandLineCallable executeCommandLineAsCallable(Commandline cl, InputStream systemIn, StreamConsumer systemOut, StreamConsumer systemErr, int timeoutInSeconds) throws CommandLineException Immediately forks a process, returns a callable that will block until process is complete.- Parameters:
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.- Returns:
- A CommandLineCallable that provides the process return value, see
Process.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 statements - Throws:
CommandLineException
- or CommandLineTimeOutException if time out occurs
-
handleException
private static void handleException(StreamPumper streamPumper, String streamName) throws CommandLineException - Throws:
CommandLineException
-
handleException
private static void handleException(StreamFeeder streamFeeder, String streamName) throws CommandLineException - Throws:
CommandLineException
-
getSystemEnvVars
Gets the shell environment variables for this process. Note that the returned mapping from variable names to values will always be case-sensitive regardless of the platform, i.e.getSystemEnvVars().get("path")
andgetSystemEnvVars().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.- Returns:
- The shell environment variables, can be empty but never
null
. - Throws:
IOException
- If the environment variables could not be queried from the shell.- See Also:
-
getSystemEnvVars
Return the shell environment variables. IfcaseSensitive == true
, then envar keys will all be upper-case.- Parameters:
caseSensitive
- Whether environment variable keys should be treated case-sensitively.- Returns:
- Properties object of (possibly modified) envar keys mapped to their values.
- Throws:
IOException
- .- See Also:
-
isAlive
-
translateCommandline
- Throws:
Exception
-
quote
Deprecated.Put quotes around the given String if necessary.
If the argument doesn't include spaces or quotes, return it as is. If it contains double quotes, use single quotes - else surround the argument by double quotes.
- Throws:
CommandLineException
- if the argument contains both, single and double quotes.
-
quote
Deprecated.Put quotes around the given String if necessary.
If the argument doesn't include spaces or quotes, return it as is. If it contains double quotes, use single quotes - else surround the argument by double quotes.
- Throws:
CommandLineException
- if the argument contains both, single and double quotes.
-
quote
public static String quote(String argument, boolean escapeSingleQuotes, boolean escapeDoubleQuotes, boolean wrapExistingQuotes) throws CommandLineException Deprecated.- Throws:
CommandLineException
-
toString
-
StringUtils.quoteAndEscape(String, char, char[], char[], char, boolean)
,StringUtils.quoteAndEscape(String, char, char[], char, boolean)
, orStringUtils.quoteAndEscape(String, char)
instead.