aspose file tools*
The moose likes Beginning Java and the fly likes Need to run 3 .bat files using JAVA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Need to run 3 .bat files using JAVA" Watch "Need to run 3 .bat files using JAVA" New topic
Author

Need to run 3 .bat files using JAVA

Mahesh Bhatt
Ranch Hand

Joined: Sep 15, 2004
Posts: 88
Hi,

I am quite new to Java. I am trying to make a utility for myself that can do the following:

1) go and execute C:\start\start1.bat
2) go and execute C:\start\start2.bat
3) go and execute C:\start\start3.bat

Right now what I do is personally go to these folders and click on these files to start them (so I get three command window popups and they are running the commands that are present in these files).
If I am able to make a java program to execute these three steps in just one hit I can reduce clicking three files. Please help me out in this, I know that this is like asking someone to do homework but I would appreciate any pointers or help.

Thanks


Impossible is I M Possible
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41877
    
  63
Java isn't really suited for this job. It would be easier to write a shell script that does this. If you really want to use Java, check out java.lang.Runtime.exec. It lets you execute processes that run outside of the JVM.


Ping & DNS - my free Android networking tools app
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 686
On Windows, you could make a batch file that CALLs the other batch files.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

And I have no idea why, given prashant's admitted newbie-ness, we're discussing this in the Advanced Java forum! I'm moving this to Java in General (Beginner) for followup questions about Runtime.exec().


[Jess in Action][AskingGoodQuestions]
Jeremy Brandon
Greenhorn

Joined: Sep 02, 2004
Posts: 13
I am not a big fan of setting off executables from Java, but if you really had to, you can always do something along these lines:

String executableFile = "c:\\exeFiles\\target.exe";

try
{
Process p = Runtime.getRuntime().exec(executableFile);
}

catch(IOException ex) { Code you wish to handle the exception }
catch(InterruptedException ex) { Code you wish to handle the exception }

[ September 02, 2005: Message edited by: Jeremy Brandon ]
[ September 02, 2005: Message edited by: Jeremy Brandon ]

SCJP 1.4<br />CCNA
Mahesh Bhatt
Ranch Hand

Joined: Sep 15, 2004
Posts: 88
Thanks a lot guys.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need to run 3 .bat files using JAVA