Hi,
Is there a way to execute a .bat file from within my java code?
Something like WinExec?
Thanks.
Andrew Thompson - 27 Dec 2005 09:27 GMT
> Is there a way to execute a .bat file from within my java code?
<http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Runtime.html#exec(java.lang.String)>
(and overloaded variants) though it might make more sense
to 'exec' the individual commands in the .bat file of interest.
HTH

Signature
Andrew Thompson
physci, javasaver, 1point1c, lensescapes - athompson.info/andrew
Roedy Green - 27 Dec 2005 10:13 GMT
>Is there a way to execute a .bat file from within my java code?
>Something like WinExec?
see http://mindprod.com/jgloss/exec.html

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Shameek - 28 Dec 2005 06:54 GMT
I have a sample code which shows how to run a .bat file (or any
executable file from java). :
import java.io.*;
class test{
public static void main(String arg[]){
try{
String command = "cmd /C start C:/test.bat ";
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(command);
}catch (IOException e) {
e.printStackTrace();
}
}
}
Here the .bat file is present in c:\test folder.
Hope this will b of help to u.
Guillaume - 02 Jan 2006 23:09 GMT
Meidan:
> Is there a way to execute a .bat file from within my java code?
> Something like WinExec?
Something like:
Runtime.exec("command.com /c your.bat");

Signature
My desktop is worth a million of dollars. Put an icon on it.
http://www.milliondollarscreenshot.com/
Simon OUALID - 03 Jan 2006 07:33 GMT
> Meidan:
>
[quoted text clipped - 3 lines]
> Something like:
> Runtime.exec("command.com /c your.bat");
Or cmd.exe for win2k / xp.
More information on how to make a good use of the Runtime's exec method
here :
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html