Running Windows .exe file with multiple arguments using Java ProcessBuilder is not producing any output file as expected

↘锁芯ラ 提交于 2019-12-13 06:18:45

问题


I am trying to run an external .exe program in Windows 7 from my Java code using ProcessBuilder

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

However, when I run this standalone .exe from Windows using cmd it outputs the results in the command prompt as well as producing a file containing the results. I am not seeing any of these two happening while running the .exe from Java

Any kind suggestions what I am missing out?


回答1:


try to use this to set working directory :

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


来源:https://stackoverflow.com/questions/17809295/running-windows-exe-file-with-multiple-arguments-using-java-processbuilder-is-n

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!