This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes problem running .BAT file from the Java app Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Reply locked New topic

problem running .BAT file from the Java app

Manoj Gundawar
Ranch Hand

Joined: Nov 17, 2002
Posts: 169
I need to run .BAT file from Java application.
here is the code I am following:
class test....{
There are three commands to execute in the .Bat file
SET PATH=%PATH%;C:\j2sdk1.4.0\bin;
SET CLASSPATH=.;C:\j2sdk1.4.0\classes;C:\j2sdk1.4.0;C:\mq.jar;
java Jtier

But it dosent work. It dosent execute hte JTier application, when I run test java program.
But when I change the code as:
class test....{
Runtime.getRuntime().exec("java Jtier");
It works.
Please help me to understand how it works. Does my .bat file should have only one command to execute? Can this not execute mulitple commands?
Please let me know.

Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
Does this have something to do with the Developer Certification exam? I think you probably want to post this in another forum, such as Java in General (Intermediate). If you're using a BAT file as part of your developer exam, your code is very unlikely to run on other machines (esp non-Wndows machines).

"I'm not back." - Bill Harding, Twister
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11404

Since Manoj opened the same question in JiG (Intermediate) following Jim's comment, I have closed this thread.
Please post any comments in Manoj's other thread for this question.

The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
subject: problem running .BAT file from the Java app
Similar Threads
Why is Runtime.getRuntime().exec() not working in JSP?
executing dos commands in java
executing java commands using a java program
run bat file within java
How to execute .BAT thru java Application