sbool nohup_debug; sbool nohup_noSlashB; sbool nohup_keepScriptFile; static new ThreadLocal nohup_exitValue; public static File nohup(File cmd) { ret nohup(f2s(cmd)); } public static File nohup(String cmd) ctex { File outFile = File.createTempFile("nohup_" + nohup_sanitize(cmd) + "_", ".out"); nohup(cmd, outFile, false); return outFile; } /** outFile takes stdout and stderr. */ public static void nohup(String cmd, File outFile, boolean append) ctex { S command = nohup_makeNohupCommand(cmd, outFile, append); File scriptFile = File.createTempFile("_realnohup", isWindows() ? ".bat" : ""); print("[nohup] " + command); try { if (nohup_debug) print("[nohup] Script file: " + scriptFile.getPath()); saveTextFile(scriptFile.getPath(), command); S[] command2; if (isWindows()) if (nohup_noSlashB) command2 = new String[] {"cmd", "/c", "start", scriptFile.getPath() }; else command2 = new String[] {"cmd", "/c", "start", "/b", scriptFile.getPath() }; else command2 = new String[] {"/bin/bash", scriptFile.getPath() }; print("[nohup] " + joinWithSpace(quoteAll(command2))); Process process = Runtime.getRuntime().exec(command2); try { process.waitFor(); } catch (InterruptedException e) { throw new RuntimeException(e); } int value = process.exitValue(); nohup_exitValue.set(value); if (value != 0) warn("nohup exit value != 0: " + value); //System.out.println("exit value: " + value); } finally { if (!nohup_keepScriptFile && !isWindows()) scriptFile.delete(); } } sS nohup_makeNohupCommand(String cmd, File outFile, boolean append) { mkdirsForFile(outFile); String command; if (isWindows()) command = cmd + (append ? " >>" : " >") + winQuote(outFile.getPath()) + " 2>&1"; else command = "nohup " + cmd + (append ? " >>" : " >") + bashQuote(outFile.getPath()) + " 2>&1 &"; ret command; }