Package org.apache.commons.exec
Class CommandLine
java.lang.Object
org.apache.commons.exec.CommandLine
CommandLine objects help handling command lines specifying processes to
execute. The class can be used to a command line by an application.
- Version:
- $Id: CommandLine.java 1613094 2014-07-24 12:20:14Z ggregory $
-
Constructor Summary
ConstructorsConstructorDescriptionCommandLine
(File executable) Create a command line without any arguments.CommandLine
(String executable) Create a command line without any arguments.CommandLine
(CommandLine other) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionaddArgument
(String argument) Add a single argument.addArgument
(String argument, boolean handleQuoting) Add a single argument.addArguments
(String addArguments) Add multiple arguments.addArguments
(String[] addArguments) Add multiple arguments.addArguments
(String[] addArguments, boolean handleQuoting) Add multiple arguments.addArguments
(String addArguments, boolean handleQuoting) Add multiple arguments.String[]
Returns the expanded and quoted command line arguments.Returns the executable.boolean
isFile()
Was a file being used to set the executable?static CommandLine
Create a command line from a string.static CommandLine
Create a command line from a string.void
setSubstitutionMap
(Map<String, ?> substitutionMap) Set the substitutionMap to expand variables in the command line.toString()
Stringify operator returns the command line as a string.String[]
Returns the command line as an array of strings.
-
Constructor Details
-
CommandLine
Create a command line without any arguments.- Parameters:
executable
- the executable
-
CommandLine
Create a command line without any arguments.- Parameters:
executable
- the executable file
-
CommandLine
Copy constructor.- Parameters:
other
- the instance to copy
-
-
Method Details
-
parse
Create a command line from a string.- Parameters:
line
- the first element becomes the executable, the rest the arguments- Returns:
- the parsed command line
- Throws:
IllegalArgumentException
- If line is null or all whitespace
-
parse
Create a command line from a string.- Parameters:
line
- the first element becomes the executable, the rest the argumentssubstitutionMap
- the name/value pairs used for substitution- Returns:
- the parsed command line
- Throws:
IllegalArgumentException
- If line is null or all whitespace
-
getExecutable
Returns the executable.- Returns:
- The executable
-
isFile
Was a file being used to set the executable?- Returns:
- true if a file was used for setting the executable
-
addArguments
Add multiple arguments. Handles parsing of quotes and whitespace.- Parameters:
addArguments
- An array of arguments- Returns:
- The command line itself
-
addArguments
Add multiple arguments.- Parameters:
addArguments
- An array of argumentshandleQuoting
- Add the argument with/without handling quoting- Returns:
- The command line itself
-
addArguments
Add multiple arguments. Handles parsing of quotes and whitespace. Please note that the parsing can have undesired side-effects therefore it is recommended to build the command line incrementally.- Parameters:
addArguments
- An string containing multiple arguments.- Returns:
- The command line itself
-
addArguments
Add multiple arguments. Handles parsing of quotes and whitespace. Please note that the parsing can have undesired side-effects therefore it is recommended to build the command line incrementally.- Parameters:
addArguments
- An string containing multiple arguments.handleQuoting
- Add the argument with/without handling quoting- Returns:
- The command line itself
-
addArgument
Add a single argument. Handles quoting.- Parameters:
argument
- The argument to add- Returns:
- The command line itself
- Throws:
IllegalArgumentException
- If argument contains both single and double quotes
-
addArgument
Add a single argument.- Parameters:
argument
- The argument to addhandleQuoting
- Add the argument with/without handling quoting- Returns:
- The command line itself
-
getArguments
Returns the expanded and quoted command line arguments.- Returns:
- The quoted arguments
-
getSubstitutionMap
- Returns:
- the substitution map
-
setSubstitutionMap
Set the substitutionMap to expand variables in the command line.- Parameters:
substitutionMap
- the map
-
toStrings
Returns the command line as an array of strings.- Returns:
- The command line as an string array
-
toString
Stringify operator returns the command line as a string. Parameters are correctly quoted when containing a space or left untouched if the are already quoted.
-