这是我使用的代码:
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec("cmd /C cd C:/Users/ASUS/Desktop/semantics/semantics/bin");
process = runtime.exec("java test \"abc\" \"def\"");
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line = "", tmp;
while ((tmp = br.readLine()) != null) {
line += tmp;
}
System.out.println(line);
我尝试使用诸如“cmd /C dir”之类的命令并且得到了正确的返回值。
这是我的测试应用程序:
import semantics.Compare;
public class USAGE {
public static void main(String[] args) {
String a = args[0];
String b = args[1];
Compare c = new Compare(a,b);
System.out.println(c.getResult());
}
}