I am trying to run a command in the terminal in java. This is the code I wrote so far:
public class Terminal {
public static void runCommand(String command) {
LogManager.log("Recieved command: " + command);
try {
ProcessBuilder builder = new ProcessBuilder();
String[] args = command.split(" ");
builder.command(args);
builder.directory(FileManager.getDir());
Process process = builder.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = "";
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
//Runtime.getRuntime().exec(command);
} catch (IOException e) { LogManager.error(e.toString()); }
}
}
I am reading documentation and tutorials for ProcessBuilder and I am not sure what I am doing wrong since nothing happens when I run this. This is ran when the program starts:
Terminal.runCommand("/bin/bash -c 'echo Test'");
It should work, the command works in the terminal fine but it does not.