1

I have an java program that runs external programs executing commandline parameters. After making some searches I found that some people are running .bat files for doing that. Which is best way for this case?

  • Execute command
  • Execute bat file

Also I wonder anybody that experienced about running external applications from java, which problems they come up and are there any unsolvable problems ?

Thanks,

Alex K.
  • 171,639
  • 30
  • 264
  • 288
emin
  • 742
  • 9
  • 21
  • http://stackoverflow.com/questions/506154/runtime-class-in-java and http://stackoverflow.com/questions/480433/launch-jvm-process-from-a-java-application-use-runtime-exec/480463#480463 – Azodious Jan 17 '12 at 13:52

2 Answers2

2

You can use the exec method

Process p = Runtime.getRuntime().exec("myFile.exe");

If you want to wait for it to finish you can do

p.waitFor();
MrKiane
  • 4,803
  • 2
  • 17
  • 27
0

Use the apache exec library. http://commons.apache.org/exec/

It tries to solve the issues mentioned here: http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

The article describes all the traps that Runtime.exec() throws at you..

sethu
  • 8,181
  • 7
  • 39
  • 65