Source:
<code>public static Process startApplication(String applicationPathAndArguments, String workingDirectory, OS_NAMES executeOnPlatform) throws IOException { if (!isCurrentOS(executeOnPlatform) || applicationPathAndArguments == null || "".equals(applicationPathAndArguments.trim())) { return null; } applicationPathAndArguments = applicationPathAndArguments.trim(); try { List<String> command = new ArrayList<>(); int cmdEndIndex = 0; if (applicationPathAndArguments.indexOf("\"") == 0) { cmdEndIndex = applicationPathAndArguments.substring(1).indexOf('"'); if (cmdEndIndex > -1) { cmdEndIndex = cmdEndIndex + 2; } } else { cmdEndIndex = applicationPathAndArguments.indexOf(" "); } if (cmdEndIndex < 0) { logger.warning("Only command, no arguments: " + applicationPathAndArguments); cmdEndIndex=applicationPathAndArguments.length(); } String cmdString = applicationPathAndArguments.substring(0, cmdEndIndex); command.add(FilenameUtils.separatorsToSystem(cmdString)); String arguments = ""; try { arguments = applicationPathAndArguments.substring(cmdEndIndex + 1); } catch (IndexOutOfBoundsException e) { logger.fine("No cmd arguments found."); } <START> Matcher m = Pattern.compile("([^\"]\\S*|\".+?\")\\s*").matcher(arguments); <END> while (m.find()) { String token = m.group(1).replace("\"", ""); command.add(token); logger.fine("adding argument: " + token); } return startApplication(command, workingDirectory); } catch (Exception e) { throw new RuntimeException("Could not construct command string: " + e.getMessage()); } }</code><technical_language>Please provide link pattern tester examples of tested inputs. Is argument matched correctly? -e "echo "This is a test" > output.txt"</technical_language>

Target:
public static Process startApplication(String applicationPathAndArguments, String workingDirectory, OS_NAMES executeOnPlatform) throws IOException { if (!isCurrentOS(executeOnPlatform) || applicationPathAndArguments == null || "".equals(applicationPathAndArguments.trim())) { return null; } applicationPathAndArguments = applicationPathAndArguments.trim(); try { List<String> command = new ArrayList<>(); int cmdEndIndex = 0; if (applicationPathAndArguments.indexOf("\"") == 0) { cmdEndIndex = applicationPathAndArguments.substring(1).indexOf('"'); if (cmdEndIndex > -1) { cmdEndIndex = cmdEndIndex + 2; } } else { cmdEndIndex = applicationPathAndArguments.indexOf(" "); } if (cmdEndIndex < 0) { logger.warning("Only command, no arguments: " + applicationPathAndArguments); cmdEndIndex=applicationPathAndArguments.length(); } String cmdString = applicationPathAndArguments.substring(0, cmdEndIndex); command.add(FilenameUtils.separatorsToSystem(cmdString)); String arguments = ""; try { arguments = applicationPathAndArguments.substring(cmdEndIndex + 1); } catch (IndexOutOfBoundsException e) { logger.fine("No cmd arguments found."); } Matcher m = Pattern.compile("(([^\\s\"]+)|(\".+?\"))\\s*").matcher(arguments); while (m.find()) { String token = m.group(1).replace("\"", ""); command.add(token); logger.fine("adding argument: " + token); } return startApplication(command, workingDirectory); } catch (Exception e) { throw new RuntimeException("Could not construct command string: " + e.getMessage()); } }