@Test public void testEscapeForBourneMultiLine() { List<String> argv = Arrays.asList("/usr/bin/foo", "--value", "\n\r\f\u0011\t\\'"); String s = Executor.escapeForShell(argv, true, false); assertEquals("/usr/bin/foo \\" + System.lineSeparator() + "\t--value \\" + System.lineSeparator() + "\t$'\\n\\r\\f\\v\\t\\\\\\''", s); }
public static String escapeForShell(List<String> argv, boolean multiline, boolean isWindows) { StringBuilder result = new StringBuilder(); for (int i = 0; i < argv.size(); ++i) { if (multiline && i > 0) { result.append("\t"); } String arg = argv.get(i); result.append(isWindows ? maybeEscapeForPowerShell(arg) : maybeEscapeForSh(arg)); if (i + 1 < argv.size()) { if (!multiline) { result.append(" "); } else { result.append(isWindows ? " `" : " \\"); result.append(System.lineSeparator()); } } } return result.toString(); }
Executor { public static String escapeForShell(List<String> argv, boolean multiline, boolean isWindows) { StringBuilder result = new StringBuilder(); for (int i = 0; i < argv.size(); ++i) { if (multiline && i > 0) { result.append("\t"); } String arg = argv.get(i); result.append(isWindows ? maybeEscapeForPowerShell(arg) : maybeEscapeForSh(arg)); if (i + 1 < argv.size()) { if (!multiline) { result.append(" "); } else { result.append(isWindows ? " `" : " \\"); result.append(System.lineSeparator()); } } } return result.toString(); } }
Executor { public static String escapeForShell(List<String> argv, boolean multiline, boolean isWindows) { StringBuilder result = new StringBuilder(); for (int i = 0; i < argv.size(); ++i) { if (multiline && i > 0) { result.append("\t"); } String arg = argv.get(i); result.append(isWindows ? maybeEscapeForPowerShell(arg) : maybeEscapeForSh(arg)); if (i + 1 < argv.size()) { if (!multiline) { result.append(" "); } else { result.append(isWindows ? " `" : " \\"); result.append(System.lineSeparator()); } } } return result.toString(); } Executor(String[] cmd);  Executor(List<String> cmdList);  Executor(List<String> cmdList, File workingDirectory);  Executor(List<String> cmdList, File workingDirectory, int timeout);  Executor(List<String> cmdList, File workingDirectory, boolean UseTimeout); }
Executor { public static String escapeForShell(List<String> argv, boolean multiline, boolean isWindows) { StringBuilder result = new StringBuilder(); for (int i = 0; i < argv.size(); ++i) { if (multiline && i > 0) { result.append("\t"); } String arg = argv.get(i); result.append(isWindows ? maybeEscapeForPowerShell(arg) : maybeEscapeForSh(arg)); if (i + 1 < argv.size()) { if (!multiline) { result.append(" "); } else { result.append(isWindows ? " `" : " \\"); result.append(System.lineSeparator()); } } } return result.toString(); } Executor(String[] cmd);  Executor(List<String> cmdList);  Executor(List<String> cmdList, File workingDirectory);  Executor(List<String> cmdList, File workingDirectory, int timeout);  Executor(List<String> cmdList, File workingDirectory, boolean UseTimeout); int exec(); int exec(boolean reportExceptions); int exec(final boolean reportExceptions, StreamHandler handler); String getOutputString(); Reader getOutputReader(); InputStream getOutputStream(); String getErrorString(); Reader getErrorReader(); InputStream getErrorStream(); static void registerErrorHandler(); static String escapeForShell(List<String> argv, boolean multiline, boolean isWindows); }
Executor { public static String escapeForShell(List<String> argv, boolean multiline, boolean isWindows) { StringBuilder result = new StringBuilder(); for (int i = 0; i < argv.size(); ++i) { if (multiline && i > 0) { result.append("\t"); } String arg = argv.get(i); result.append(isWindows ? maybeEscapeForPowerShell(arg) : maybeEscapeForSh(arg)); if (i + 1 < argv.size()) { if (!multiline) { result.append(" "); } else { result.append(isWindows ? " `" : " \\"); result.append(System.lineSeparator()); } } } return result.toString(); } Executor(String[] cmd);  Executor(List<String> cmdList);  Executor(List<String> cmdList, File workingDirectory);  Executor(List<String> cmdList, File workingDirectory, int timeout);  Executor(List<String> cmdList, File workingDirectory, boolean UseTimeout); int exec(); int exec(boolean reportExceptions); int exec(final boolean reportExceptions, StreamHandler handler); String getOutputString(); Reader getOutputReader(); InputStream getOutputStream(); String getErrorString(); Reader getErrorReader(); InputStream getErrorStream(); static void registerErrorHandler(); static String escapeForShell(List<String> argv, boolean multiline, boolean isWindows);  }