SubServers-2/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Executable.java

31 lines
1.1 KiB
Java
Raw Normal View History

2016-12-24 05:55:17 +01:00
package net.ME1312.SubServers.Bungee.Host;
2016-12-05 04:21:04 +01:00
import java.io.File;
/**
* Executable String Handler Class
2016-12-05 04:21:04 +01:00
*/
public class Executable {
private Executable() {}
2016-12-05 04:21:04 +01:00
/**
* Format a command to be executed
2016-12-05 04:21:04 +01:00
*
* @param gitbash Git Bash location (optional)
* @param exec Executable String
* @return
2016-12-05 04:21:04 +01:00
*/
public static String[] parse(String gitbash, String exec) {
String[] cmd;
if (System.getProperty("os.name").toLowerCase().startsWith("windows")) {
if (gitbash != null && (exec.startsWith("bash ") || exec.startsWith("sh ")))
2019-01-05 05:35:20 +01:00
exec = '"' + gitbash + ((gitbash.endsWith(File.separator))?"":File.separator) + "bin" + File.separatorChar + "sh.exe\" -lc \"" +
exec.replace("\\", "/\\").replace("\"", "\\\"").replace("^", "^^").replace("%", "^%").replace("&", "^&").replace("<", "^<").replace(">", "^>").replace("|", "^|") + '"';
cmd = new String[]{"cmd.exe", "/q", "/c", '"'+exec+'"'};
2016-12-05 04:21:04 +01:00
} else {
cmd = new String[]{"sh", "-lc", exec};
2016-12-05 04:21:04 +01:00
}
return cmd;
2016-12-05 04:21:04 +01:00
}
}