External program execution in Java under windows

By Angsuman Chakraborty, Gaea News Network
Monday, January 12, 2004

Question? Amitava Ghosh wrote at caljug:

Dear all,
I am trying to call an executable(written in C++) inside a java code through a
batch file(where the parameters for the C++ executable are stored).
When I am using
Process p = Runtime.getRunTime().exec(”cppexe.bat”)
it is working fine but when I am using start to run the batch process in a new window as in
Process p = Runtime.getRuntime().exec(”start cppexe.bat”)
I am getting an IOException Cannot create process etc etc

Answer: start is a command of cmd.exe (under Windows NT/2000 etc.). So you should run it instead:
Process p = Runtime.getRuntime().exec(”cmd /c start cppexe.bat”);

Filed under: Java Software
Discussion

Radha krishnan
July 29, 2007: 11:00 am

hey thank u very much
i was searching how to run cmd.exe in a java program
u helped me a lot
once again thank u very much

December 3, 2004: 6:16 pm

You can invoke start if you prefix it with cmd.exe, essentially then cmd.exe is the command and the rest are parameters. However why would you need to do start?

> To run the Windows command interpreter, execute either command.com or cmd.exe, depending on the Windows operating system you use. Listing 4.5 runs a copy of the Windows command interpreter and then executes the user-supplied command (e.g., dir).

Yes, you can do re-directions using the same trick mentioned above.

Actually the url you supplied gives the above solutions too.


Olivier
February 29, 2004: 10:04 pm

Runtime.exec() is not a command line!
You cannot do starts, redirections, etc.
Check this article:
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

YOUR VIEW POINT
NAME : (REQUIRED)
MAIL : (REQUIRED)
will not be displayed
WEBSITE : (OPTIONAL)
YOUR
COMMENT :