Answers for "java run linux command and get output"

1

How to execute Shell Commands with Java and print the output directly while executing the command

ProcessBuilder pb = new ProcessBuilder("ping", "localhost");
pb.inheritIO();
try {
    Process p = pb.start();
    int exitStatus = p.waitFor();
    System.out.println(exitStatus);
}
catch (InterruptedException | IOException x) {
    x.printStackTrace();
}
Posted by: Guest on October-27-2021

Code answers related to "java run linux command and get output"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language