How do I get the bash command exit code from a Process run from within Java?
问题 I have a program which is: import java.io.*; import java.util.*; public class ExecBashCommand { public static void main(String args[]) throws IOException { if (args.length <= 0) { System.err.println("Need command to run"); System.exit(-1); } Runtime runtime = Runtime.getRuntime(); Process process = runtime.exec("./nv0914 < nv0914.challenge"); Process process1 = runtime.exec("echo ${?}"); InputStream is = process1.getInputStream(); InputStreamReader isr = new InputStreamReader(is);