
com.crabshue.commons.process.helpers.ProcessHelper Maven / Gradle / Ivy
package com.crabshue.commons.process.helpers;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ProcessHelper {
private static final String SPLIT_EXPRESSION = "(\"[^\"\\\\]*(?:\\\\[\\S\\s][^\"\\\\]*)*\"|'[^'\\\\]*(?:\\\\[\\S\\s][^'\\\\]*)*'|\\/[^\\/\\\\]*(?:\\\\[\\S\\s][^\\/\\\\]*)*\\/[gimy]*(?=\\s|$)|(?:\\\\\\s|\\S)+)";
/**
* Split command into argument array.
*
* @param command The command to split.
* @return The argument array.
*/
public static String[] splitCommand(String command) {
Pattern pattern = Pattern.compile(SPLIT_EXPRESSION);
Matcher matcher = pattern.matcher(command);
List splitCommand = new ArrayList<>();
while(matcher.find()) {
String match = matcher.group();
if( match != null ) {
splitCommand.add(match.trim());
}
}
return splitCommand.toArray(new String[0]);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy