我正在尝试运行一个外部程序,并将自定义参数放置在文本字段中。
这是我的代码:
String customPARAM = textfield.getText();
try {
new ProcessBuilder("MyEXE.exe", "-param1 " + customPARAM).start();
} catch (IOException ex) {
Logger.getLogger(MainMenu.class.getName()).log(Level.SEVERE, null, ex);
}
问题是输出不接受我的 customPARAM
并且它执行类似 MyEXE.exe -param1
的操作。
最佳答案
用“,
”代替空格分隔参数:
new ProcessBuilder("MyEXE.exe", "-param1 ", customPARAM, ...).start();
参见this :ProcessBuilder(字符串...命令)
。
关于java - 使用自定义参数运行外部程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38164828/