A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Java SE 8 for the Really Impatient
this week in the
Java in General
execute batch files in java
Joined: Jun 28, 2005
Jun 28, 2005 04:43:00
I have 2 batch files "run.bat" and "run1.bat". They reside in C:/bin/. Contents of these files are as follows: Observe that "run.bat" is calling "run1.bat".
class reside in E;/bin and it looks like...
String command = "c:/bin/run.bat";
Process child = Runtime.getRuntime().exec(command);
Result of this java code execution is that it prints "Sanjay" and then its not able to call "run1.bat"
This is because the directory where these batch files reside is different from the dir where my java class is. If I change "run.bat" as follows, it works fine and prints "Sanghavi".
But I dont want to change the batch file instead is there a way I can achieve this with some code changes in java or some other way to do this?
Thanks in advance
author and iconoclast
Joined: Jul 08, 2003
Jun 28, 2005 05:28:00
Welcome to JavaRanch!
This ought to work as long as the directory in which the BAT files are located in on your PATH.
[Jess in Action]
Joined: Oct 10, 2001
Jun 28, 2005 06:29:00
"cmd /c c:/bin/run.bat"
instead? Like EFH says, it should work if the bat files are in the path.
You could change the run1.bat to do (assuming windows NT or better)
Then provided both run1 and run2 are in the same directory, you should be able to put them anyway.
I have no java certifications. This makes me a bad programmer. Ignore my post.
I agree. Here's the link:
subject: execute batch files in java
PATH Vs. CLASSPATH settings
Help me to create batch file
how to redirect the tomcat (5.0) console output to a text file
Jboss not Running/starting
Setting the classpath
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014