Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
The easiest call of the ProcessBuilder
ProcessBuilder pb = new ProcessBuilder("ls", "-al");
pb.directory(Paths.get("/tmp").toFile());
pb.redirectErrorStream(true);
Process process = pb.start();
try (var infoStream = process.getInputStream()) {
infoStream.transferTo(System.out);
}
int exitCode = process.waitFor();
if(exitCode == 0)
System.out.println("Command successful processed.");
else
System.out.println("Command stops with exit-code: " + exitCode);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment