我有一个程序是:
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);
BufferedReader br = new BufferedReader(isr);
String line;
//System.out.printf("Output of running %s is:", Arrays.toString(args));
while ((line = br.readLine()) != null) {
System.out.println(line);
}
}
}
注意:nv0914 是一个 bash 可执行文件,而 nv0914.challenge 是一个文本文件。当我在终端中运行任何正常命令时,然后如果我使用echo ${?}
. 现在我想通过使用程序来做同样的事情,但程序只是给出输出${?}
。请帮帮我!