Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

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();
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #How #execute #Shell #Commands #Java #print #output #executing #command
ADD COMMENT
Topic
Name
1+2 =