📜  如何使用 Java 执行 Shell 命令并在执行命令时直接打印输出 - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:42.060000             🧑  作者: Mango

代码示例1
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();
}