Take the 2-minute tour ×

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?

share|improve this question
1) Read (and implement) all the recommendations of When Runtime.exec() won't. That might solve the problem. If not, it should provide more information as to the reason it failed. Then ignore that it refers to exec and (continue to) build the Process using a ProcessBuilder. 2) For better help sooner, post an SSCCE. –  Andrew Thompson Jul 23 '13 at 11:48
What are you doing after pb.start() in your program? –  Ingo Jul 23 '13 at 11:48
@Ingo .. absolutely nothing after pb.start(); just end of the class –  jmkam Jul 23 '13 at 11:59
add comment

1 Answer

up vote 2 down vote accepted

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");
Process process = pb.start();
share|improve this answer
Running the suggested code produces the following error: Exception in thread "main" java.io.IOException: Cannot run program "hmetis.exe" (in directory "C:\hMetis\1.5.3-win32"): CreateProcess error=2, The system cannot find the file specified –  jmkam Jul 23 '13 at 12:10
Sorry, i add "cmd", "/c","start", to the arguments , it should work now. –  Gladiator Jul 23 '13 at 13:03
it worked !!! Thanks a lot for giving a absolute correct answer. I am now getting the expected results as well as the output files. –  jmkam Jul 23 '13 at 13:20
add comment

Your Answer


