From eea13b22a004beff9a078eddd564e2e345a55d33 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 9 Jan 2023 01:32:57 -0500 Subject: [PATCH] Using ProcessBuilding instead of exec() --- src/discord/handlers/DevRequestHandler.java | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/discord/handlers/DevRequestHandler.java b/src/discord/handlers/DevRequestHandler.java index 9331375e..69e040cf 100644 --- a/src/discord/handlers/DevRequestHandler.java +++ b/src/discord/handlers/DevRequestHandler.java @@ -20,7 +20,8 @@ public class DevRequestHandler { String serverCommand; String commandArgument = ""; - String execString = ""; + String commandString = ""; + ProcessBuilder processBuilder; // Early exit if database unavailable or is not an admin @@ -40,27 +41,30 @@ public class DevRequestHandler { switch (serverCommand) { case "build" : - execString = "mbdevbuild.sh"; + commandString = "mbdevbuild.sh"; break; case "restart": - execString = "mbdevrestart.sh"; + commandString = "mbdevrestart.sh"; break; case "debug": - execString = "mbdevdebug.sh"; + commandString = "mbdevdebug.sh"; break; case "shutdown": - execString = "mbdevkill.sh"; + commandString = "mbdevkill.sh"; break; default: break; } - if (execString.isEmpty() == false) { + if (commandString.isEmpty() == false) { + + processBuilder = new ProcessBuilder("sh", "-c", commandString, commandArgument); try { - Runtime.getRuntime().exec(new String[]{execString, commandArgument}); + processBuilder.start(); } catch (IOException e) { - e.printStackTrace(); + throw new RuntimeException(e); } + MagicBot.sendResponse(event, "Executed on dev: " + serverCommand + " " + commandArgument); Logger.info(event.getAuthor().getName() + " told dev to " + serverCommand + " " + commandArgument); }