So führen Sie Shell -Befehle mit Java aus und drucken Sie die Ausgabe direkt aus, während Sie den Befehl ausführen

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();
}
Friendly Fowl