我正在尝试使用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时,我没有看到这两种情况的发生

有什么建议让我错过吗?

最佳答案

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

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();

关于java - 使用Java ProcessBuilder运行具有多个参数的Windows .exe文件不会按预期产生任何输出文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17809295/

10-13 03:41