Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need to run 3 .bat files using JAVA

 
Mahesh Bhatt
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Norm Radder
Ranch Hand
Posts: 892
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On Windows, you could make a batch file that CALLs the other batch files.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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().
 
Jeremy Brandon
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Mahesh Bhatt
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot guys.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic