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;
|
|
|
|
|
|
|
|
/**
|
2019-01-04 22:51:58 +01:00
|
|
|
* Executable String Handler Class
|
2016-12-05 04:21:04 +01:00
|
|
|
*/
|
2019-01-04 22:51:58 +01:00
|
|
|
public class Executable {
|
|
|
|
private Executable() {}
|
2016-12-05 04:21:04 +01:00
|
|
|
|
|
|
|
/**
|
2019-01-04 22:51:58 +01:00
|
|
|
* Format a command to be executed
|
2016-12-05 04:21:04 +01:00
|
|
|
*
|
2019-01-04 22:51:58 +01:00
|
|
|
* @param gitbash Git Bash location (optional)
|
|
|
|
* @param exec Executable String
|
|
|
|
* @return
|
2016-12-05 04:21:04 +01:00
|
|
|
*/
|
2019-01-04 22:51:58 +01:00
|
|
|
public static String[] parse(String gitbash, String exec) {
|
|
|
|
String[] cmd;
|
2019-01-05 00:32:01 +01:00
|
|
|
if (System.getProperty("os.name").toLowerCase().startsWith("windows")) {
|
2019-01-04 22:51:58 +01:00
|
|
|
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("|", "^|") + '"';
|
2019-01-04 22:51:58 +01:00
|
|
|
cmd = new String[]{"cmd.exe", "/q", "/c", '"'+exec+'"'};
|
2016-12-05 04:21:04 +01:00
|
|
|
} else {
|
2019-01-05 00:32:01 +01:00
|
|
|
cmd = new String[]{"sh", "-lc", exec};
|
2016-12-05 04:21:04 +01:00
|
|
|
}
|
2019-01-04 22:51:58 +01:00
|
|
|
return cmd;
|
2016-12-05 04:21:04 +01:00
|
|
|
}
|
|
|
|
}
|