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);
}