The easiest call of the ProcessBuilder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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