Package org.eclipse.cdt.utils
Class CommandLineUtil
java.lang.Object
org.eclipse.cdt.utils.CommandLineUtil
Utilities to work with command line, parse arguments, etc.
- Since:
- 5.1
- Restriction:
- This class is not intended to be subclassed by clients.
- Restriction:
- This class is not intended to be instantiated by clients.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String[]argumentsToArray(String line) static String[]Parsing arguments in a shell style.static String[]Parsing arguments in a cmd style.static StringargumentsToString(String[] args, boolean encodeNewline) Converts argument array to a string suitable for passing to Bash like: This process reversesargumentsToArray(String), but does not restore the exact same results.static StringargumentsToString(Collection<String> args, boolean encodeNewline) Converts argument array to a string suitable for passing to Bash like: This process reversesargumentsToArray(String), but does not restore the exact same results.static StringargumentsToStringBash(String[] args, boolean encodeNewline) Converts argument array to a string suitable for passing to Bash like:static StringargumentsToStringWindowsCreateProcess(String[] args, boolean encodeNewline) Converts argument array to a string suitable for passing to Windows CreateProcess
-
Constructor Details
-
CommandLineUtil
public CommandLineUtil()
-
-
Method Details
-
argumentsToArray
-
argumentsToArrayUnixStyle
Parsing arguments in a shell style. i.e.["a b c" d] -> [[a b c],[d]] [a d] -> [[a],[d]] ['"quoted"'] -> [["quoted"]] [\\ \" \a] -> [[\],["],[a]] ["str\\str\a"] -> [[str\str\a]]
- Parameters:
line-- Returns:
- array of arguments, or empty array if line is null or empty
-
argumentsToArrayWindowsStyle
Parsing arguments in a cmd style. i.e.["a b c" d] -> [[a b c],[d]] [a d] -> [[a],[d]] ['"quoted"'] -> [['quoted']] [\\ \" \a] -> [[\\],["],[\a]] ["str\\str\a"] -> [[str\\str\a]]
- Parameters:
line-- Returns:
- array of arguments, or empty array if line is null or empty
-
argumentsToString
Converts argument array to a string suitable for passing to Bash like: This process reversesargumentsToArray(String), but does not restore the exact same results.- Parameters:
args- the arguments to convert and escapeencodeNewline-trueif newline (\ror\n) should be encoded- Returns:
- args suitable for passing to some process that decodes the string into an argument array
- Since:
- 9.0
-
argumentsToString
Converts argument array to a string suitable for passing to Bash like: This process reversesargumentsToArray(String), but does not restore the exact same results.- Parameters:
args- the arguments to convert and escapeencodeNewline-trueif newline (\ror\n) should be encoded- Returns:
- args suitable for passing to some process that decodes the string into an argument array
- Since:
- 6.2
-
argumentsToStringBash
Converts argument array to a string suitable for passing to Bash like:/bin/bash -c <args>
In this case the arguments array passed to exec or equivalent will be:argv[0] = "/bin/bash" argv[1] = "-c" argv[2] = argumentsToStringBashStyle(argumentsAsArray)
Replace and concatenate all occurrences of:'with"'"(as
'is used to surround everything else it has to be quoted or escaped)- newline character, if encoded, with
$'\n'(
\nis treated literally within quotes or as just 'n' otherwise, whilst supplying the newline character literally ends the command) - Anything in between and around these occurrences is surrounded by
single quotes.
(to prevent bash from carrying out substitutions or running arbitrary code with backticks or
$())
- Parameters:
args- the arguments to convert and escapeencodeNewline-trueif newline (\ror\n) should be encoded- Returns:
- args suitable for passing as single argument to bash
- Since:
- 6.2
-
argumentsToStringWindowsCreateProcess
Converts argument array to a string suitable for passing to Windows CreateProcess- Parameters:
args- the arguments to convert and escapeencodeNewline-trueif newline (\ror\n) should be encoded- Returns:
- args suitable for passing as single argument to CreateProcess on Windows
- Since:
- 6.2
-