Browse Source

Using ProcessBuilding instead of exec()

master
MagicBot 2 years ago
parent
commit
eea13b22a0
  1. 20
      src/discord/handlers/DevRequestHandler.java

20
src/discord/handlers/DevRequestHandler.java

@ -20,7 +20,8 @@ public class DevRequestHandler {
String serverCommand; String serverCommand;
String commandArgument = ""; String commandArgument = "";
String execString = ""; String commandString = "";
ProcessBuilder processBuilder;
// Early exit if database unavailable or is not an admin // Early exit if database unavailable or is not an admin
@ -40,27 +41,30 @@ public class DevRequestHandler {
switch (serverCommand) { switch (serverCommand) {
case "build" : case "build" :
execString = "mbdevbuild.sh"; commandString = "mbdevbuild.sh";
break; break;
case "restart": case "restart":
execString = "mbdevrestart.sh"; commandString = "mbdevrestart.sh";
break; break;
case "debug": case "debug":
execString = "mbdevdebug.sh"; commandString = "mbdevdebug.sh";
break; break;
case "shutdown": case "shutdown":
execString = "mbdevkill.sh"; commandString = "mbdevkill.sh";
break; break;
default: default:
break; break;
} }
if (execString.isEmpty() == false) { if (commandString.isEmpty() == false) {
processBuilder = new ProcessBuilder("sh", "-c", commandString, commandArgument);
try { try {
Runtime.getRuntime().exec(new String[]{execString, commandArgument}); processBuilder.start();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); throw new RuntimeException(e);
} }
MagicBot.sendResponse(event, "Executed on dev: " + serverCommand + " " + commandArgument); MagicBot.sendResponse(event, "Executed on dev: " + serverCommand + " " + commandArgument);
Logger.info(event.getAuthor().getName() + " told dev to " + serverCommand + " " + commandArgument); Logger.info(event.getAuthor().getName() + " told dev to " + serverCommand + " " + commandArgument);
} }

Loading…
Cancel
Save