mirror of
https://github.com/JonasunderscoreJones/ConsoleMC.git
synced 2025-10-23 02:39:17 +02:00
Code cleanup
moved threading to parent scope added issues link to mod config
This commit is contained in:
parent
8efeb1cc5b
commit
643f9497ea
3 changed files with 33 additions and 32 deletions
|
@ -76,7 +76,8 @@ public class RunCommand {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static int runCommand(String cmd, CommandContext<ServerCommandSource> context) {
|
public static int runCommand(String cmd, CommandContext<ServerCommandSource> context) {
|
||||||
return ShellCommand.execute(cmd, context);
|
new Thread(() -> {ShellCommand.execute(cmd, context);}).start();
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
public static void returnCommandOutput(String cmd, String commandFeedback, CommandContext<ServerCommandSource> context) {
|
public static void returnCommandOutput(String cmd, String commandFeedback, CommandContext<ServerCommandSource> context) {
|
||||||
String consoleLog = " [" + cmd + "]: " + commandFeedback;
|
String consoleLog = " [" + cmd + "]: " + commandFeedback;
|
||||||
|
|
|
@ -11,39 +11,38 @@ import java.io.InputStreamReader;
|
||||||
|
|
||||||
public class ShellCommand {
|
public class ShellCommand {
|
||||||
public static int execute(String command, CommandContext<ServerCommandSource> context) {
|
public static int execute(String command, CommandContext<ServerCommandSource> context) {
|
||||||
new Thread(() -> {
|
|
||||||
ProcessBuilder processBuilder = new ProcessBuilder();
|
ProcessBuilder processBuilder = new ProcessBuilder();
|
||||||
if (ConsoleMC.ISWINDOWS) {
|
if (ConsoleMC.ISWINDOWS) {
|
||||||
processBuilder.command("cmd.exe", "/c", command);
|
processBuilder.command("cmd.exe", "/c", command);
|
||||||
|
} else {
|
||||||
|
processBuilder.command("bash", "-c", command);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
Process process = processBuilder.start();
|
||||||
|
|
||||||
|
BufferedReader reader =
|
||||||
|
new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||||
|
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
RunCommand.returnCommandOutput(command, line, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
int exitCode = process.waitFor();
|
||||||
|
if (exitCode == 0) {
|
||||||
|
ConsoleMC.LOGGER.info("Exited with error code : " + exitCode);
|
||||||
} else {
|
} else {
|
||||||
processBuilder.command("bash", "-c", command);
|
ConsoleMC.LOGGER.error("Exited with error code : " + exitCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
Process process = processBuilder.start();
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
BufferedReader reader =
|
}
|
||||||
new BufferedReader(new InputStreamReader(process.getInputStream()));
|
|
||||||
|
|
||||||
String line;
|
|
||||||
while ((line = reader.readLine()) != null) {
|
|
||||||
RunCommand.returnCommandOutput(command, line, context);
|
|
||||||
}
|
|
||||||
|
|
||||||
int exitCode = process.waitFor();
|
|
||||||
if (exitCode == 0) {
|
|
||||||
ConsoleMC.LOGGER.info("Exited with error code : " + exitCode);
|
|
||||||
} else {
|
|
||||||
ConsoleMC.LOGGER.error("Exited with error code : " + exitCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,8 @@
|
||||||
],
|
],
|
||||||
"contact": {
|
"contact": {
|
||||||
"homepage": "http://jonasjones.me/consolemc",
|
"homepage": "http://jonasjones.me/consolemc",
|
||||||
"sources": "https://github.com/J-onasJones/ConsoleMC"
|
"sources": "https://github.com/J-onasJones/ConsoleMC",
|
||||||
|
"issues": "https://github.com/J-onasJones/ConsoleMC/issues"
|
||||||
},
|
},
|
||||||
|
|
||||||
"license": "CC0-1.0",
|
"license": "CC0-1.0",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue