我正在寻找一种从Java调用exe并传递特定参数的机制。我能怎么做?
Process process = new ProcessBuilder("C:\\PathToExe\\MyExe.exe").start();
InputStream is = process.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);
}
先前的代码有效。但是我无法在中传递参数。MyExe.exe接受参数。另一个问题是PathToExe有空格。ProcessBuilder似乎无法正常工作。例如:
C:\\User\\My applications\\MyExe.exe
谢谢。