Browse Source

Capturing output of remote exec() to file.

master
MagicBot 2 years ago
parent
commit
9ce06da271
  1. 7
      src/discord/handlers/DevRequestHandler.java

7
src/discord/handlers/DevRequestHandler.java

@ -13,6 +13,7 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
@ -26,6 +27,7 @@ public class DevRequestHandler {
String logString = ""; String logString = "";
ProcessBuilder processBuilder; ProcessBuilder processBuilder;
File outFile;
// Early exit if database unavailable or is not an admin // Early exit if database unavailable or is not an admin
@ -61,14 +63,17 @@ public class DevRequestHandler {
} }
processBuilder = new ProcessBuilder("/bin/sh", "-c", commandString + " " + commandArgument); processBuilder = new ProcessBuilder("/bin/sh", "-c", commandString + " " + commandArgument);
outFile = new File("devLastOut");
logString = String.join(" ",processBuilder.command().toArray(new String[0]));
try { try {
processBuilder.start(); processBuilder.start();
processBuilder.redirectOutput(outFile);
} catch (IOException e) { } catch (IOException e) {
Logger.info(e.toString()); Logger.info(e.toString());
} }
logString = String.join(" ",processBuilder.command().toArray(new String[0]));
MagicBot.sendResponse(event, "Executed on dev: " + logString); MagicBot.sendResponse(event, "Executed on dev: " + logString);
} }
} }
Loading…
Cancel
Save