Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

Executing a .bat file from my code

Thread view: 
Meidan - 27 Dec 2005 09:12 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.