Using java.lang.ProcessBuilder on a Java application running on a Linux machine (Ubuntu 18.04 specifically), what can be done such that the command executed would be able to run and not throw Permission Denied.
Here's the code:
boolean isWindows = System.getProperty("os.name")
.toLowerCase().startsWith("windows");
ProcessBuilder builder = new ProcessBuilder();
if (isWindows) {
builder.directory(new File(System.getProperty("user.home")));
builder.command("cmd.exe", "/c", command);
} else {
builder.directory(new File(System.getenv("HOME")));
builder.command("sh", "-c", command);
}
Process process = builder.start();