/** * 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. * * @param addArguments An string containing multiple arguments. * @param handleQuoting Add the argument with/without handling quoting * @return The command line itself */ public CommandLine addArguments(final String addArguments, final boolean handleQuoting) { if (addArguments != null) { final String[] argumentsArray = translateCommandline(addArguments); addArguments(argumentsArray, handleQuoting); } return this; }
/** * Create a command line from a string. * * @param line the first element becomes the executable, the rest the arguments * @param substitutionMap the name/value pairs used for substitution * @return the parsed command line * @throws IllegalArgumentException If line is null or all whitespace */ public static CommandLine parse(final String line, final Map<String, ?> substitutionMap) { if (line == null) { throw new IllegalArgumentException("Command line can not be null"); } else if (line.trim().length() == 0) { throw new IllegalArgumentException("Command line can not be empty"); } else { final String[] tmp = translateCommandline(line); final CommandLine cl = new CommandLine(tmp[0]); cl.setSubstitutionMap(substitutionMap); for (int i = 1; i < tmp.length; i++) { cl.addArgument(tmp[i]); } return cl; } }