使用Java ProcessBuilder运行具有多个参数的Windows .exe文件不会按预期生成任何输出文件

时间:2013-07-23 11:45:47

标签: java process processbuilder

我正在尝试使用ProcessBuilder

从我的Java代码在Windows 7中运行外部.exe程序
ProcessBuilder pb = new ProcessBuilder("C:\\hMetis\\1.5.3-win32\\hmetis.exe", "test.hgr", "2", "1", "10", "1", "1", "1", "0", "0");
Process process = pb.start();

但是,当我使用cmd从Windows运行此独立.exe时,它会在命令提示符下输出结果,并生成包含结果的文件。从Java

运行.exe时,我没有看到这两个中的任何一个发生

我错过了哪些建议?

1 个答案:

答案 0 :(得分:3)

尝试使用它来设置工作目录:

File f = new File("C:\\hMetis\\1.5.3-win32");
ProcessBuilder pb = new ProcessBuilder("cmd", "/c","start","hmetis.exe", "test.hgr", "2", "1", "10", "1", "1", "1", "0", "0");
pb.directory(f);
Process process = pb.start();