Package org.codehaus.plexus.util.cli
Class CommandLineUtils
java.lang.Object
org.codehaus.plexus.util.cli.CommandLineUtils
- Author:
- Trygve Laugstøl
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic classAStreamConsumerproviding consumed lines as aString.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic intexecuteCommandLine(Commandline cl, InputStream systemIn, StreamConsumer systemOut, StreamConsumer systemErr) static intexecuteCommandLine(Commandline cl, InputStream systemIn, StreamConsumer systemOut, StreamConsumer systemErr, int timeoutInSeconds) static intexecuteCommandLine(Commandline cl, StreamConsumer systemOut, StreamConsumer systemErr) static intexecuteCommandLine(Commandline cl, StreamConsumer systemOut, StreamConsumer systemErr, int timeoutInSeconds) static CommandLineCallableexecuteCommandLineAsCallable(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 PropertiesGets the shell environment variables for this process.static PropertiesgetSystemEnvVars(boolean caseSensitive) Return the shell environment variables.static booleanstatic StringDeprecated.static Stringstatic Stringquote(String argument, boolean escapeSingleQuotes, boolean escapeDoubleQuotes, boolean wrapExistingQuotes) static Stringstatic String[]translateCommandline(String toProcess) 
- 
Constructor Details- 
CommandLineUtilspublic CommandLineUtils()
 
- 
- 
Method Details- 
executeCommandLinepublic static int executeCommandLine(Commandline cl, StreamConsumer systemOut, StreamConsumer systemErr) throws CommandLineException - Throws:
- CommandLineException
 
- 
executeCommandLinepublic static int executeCommandLine(Commandline cl, StreamConsumer systemOut, StreamConsumer systemErr, int timeoutInSeconds) throws CommandLineException - Throws:
- CommandLineException
 
- 
executeCommandLinepublic static int executeCommandLine(Commandline cl, InputStream systemIn, StreamConsumer systemOut, StreamConsumer systemErr) throws CommandLineException - Throws:
- CommandLineException
 
- 
executeCommandLinepublic static int executeCommandLine(Commandline cl, InputStream systemIn, StreamConsumer systemOut, StreamConsumer systemErr, int timeoutInSeconds) throws CommandLineException - Parameters:
- cl- The command line to execute
- systemIn- The input to read from, must be thread safe
- systemOut- A consumer that receives output, must be thread safe
- systemErr- A consumer that receives system error stream output, must be thread safe
- timeoutInSeconds- 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
 
- 
executeCommandLineAsCallablepublic 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 execute
- systemIn- The input to read from, must be thread safe
- systemOut- A consumer that receives output, must be thread safe
- systemErr- A consumer that receives system error stream output, must be thread safe
- timeoutInSeconds- 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
 
- 
getSystemEnvVarsGets 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.
- See Also:
 
- 
getSystemEnvVarsReturn 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.
- See Also:
 
- 
isAlive
- 
translateCommandline- Throws:
- Exception
 
- 
quoteDeprecated.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. - Parameters:
- argument- the argument
- Returns:
- the transformed command line
- Throws:
- CommandLineException- if the argument contains both, single and double quotes.
 
- 
quote@Deprecated public static String quote(String argument, boolean wrapExistingQuotes) throws CommandLineException 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. - Parameters:
- argument- see name
- wrapExistingQuotes- see name
- Returns:
- the transformed command line
- Throws:
- CommandLineException- if the argument contains both, single and double quotes.
 
- 
quote@Deprecated public static String quote(String argument, boolean escapeSingleQuotes, boolean escapeDoubleQuotes, boolean wrapExistingQuotes) throws CommandLineException Deprecated.- Parameters:
- argument- the argument
- escapeSingleQuotes- see name
- escapeDoubleQuotes- see name
- wrapExistingQuotes- see name
- Returns:
- the transformed command line
- Throws:
- CommandLineException- some trouble
 
- 
toString
 
- 
StringUtils.quoteAndEscape(String, char, char[], char[], char, boolean),StringUtils.quoteAndEscape(String, char, char[], char, boolean), orStringUtils.quoteAndEscape(String, char)instead.