2
我试图在后台运行一个shell脚本,该脚本在我的函数/进程结束时不会终止。然而,似乎尽管没有,当java线程结束时。剧本也是如此。Java:在后台运行shell脚本
以下是样本代码。
///
/// Tries to run a script in the background
///
try {
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("nohup sh ./runner.sh > output.txt &", new String[] {}, wrkDir);
// pr.waitFor(); // Intentionally not using
} catch(Exception e) {
throw new RuntimeException(e);
}