static int backtick_exitValue; static boolean backtick_verbose; static ThreadLocal backtick_scriptFile; static String backtick(String cmd) ctex { File outFile = File.createTempFile("_backtick", ""); backtickToFile(cmd, outFile); S result = loadTextFile(outFile.getPath(), ""); if (backtick_verbose) print("[[\n" + result + "]]"); ret result; } static Process backtickToFile(String cmd, File outFile) ctex { try { Process process = backtickToFile_noWait(cmd, outFile); try { process.waitFor(); } catch (InterruptedException e) { throw new RuntimeException(e); } backtick_exitValue = process.exitValue(); if (backtick_verbose) System.out.println("Process return code: " + backtick_exitValue); ret process; } finally { deleteFile(backtick_scriptFile.get()); backtick_scriptFile.set(null); } } static Process backtickToFile_noWait(String cmd, File outFile) ctex { File scriptFile = File.createTempFile("_backtick", isWindows() ? ".bat" : ""); backtick_scriptFile.set(scriptFile); String command = cmd + " >" + bashQuote(outFile.getPath()) + " 2>&1"; //Log.info("[Backtick] " + command); if (backtick_verbose) print("backtick: command " + command); saveTextFile(scriptFile.getPath(), command); String[] command2; if (isWindows()) command2 = new String[] { scriptFile.getPath() }; else command2 = new String[] { "/bin/bash", scriptFile.getPath() }; if (backtick_verbose) print("backtick: command2 " + structure(command2)); ret Runtime.getRuntime().exec(command2); }