Forums Register Login

Not able to call a bat file from JAVA

+Pie Number of slices to send: Send
Hi

I am trying to call a .bat file from Java.
The .bat file works perfectly if I am running it manually.

Now I need it to be called from Java. But it shows a blank console window, without executing the .bat file (it is not able to load the .bat file).

Here is the code:



Please suggest what is wrong in my code.
Thanks in advance
+Pie Number of slices to send: Send
Try removing the quotes around your path. Although it is usually necessary if you type the command as one whole, this method should remove that need. Remember, you're not passing the file as an entire parameter, but the file wrapped in quotes.

Consider the following:

When run from D:, the results are as follows:
+Pie Number of slices to send: Send
If you are calling a bat file, the you should not be using Java......

You should rethink what you are doing...

While it can be done...

SHOULD IT???
+Pie Number of slices to send: Send
 

Originally posted by Steve Fahlbusch:
If you are calling a bat file, the you should not be using Java......



We know precious little about Praveen's situation to pass such a judgment. If he wants to invoke a batch file from java, let's help him. If he asks if it is a good idea or not and fills in details about what he's dealing with, then we can help him make an informed decision.
+Pie Number of slices to send: Send
You probably want to add

System.out.println(SystemFilesDir.getAbsolutePath()+"\\Batch.bat")

to see what it actually looks like. And it's entirely possible that those extra quotes are causing the problem; Windows CMD is really funny about quotes.
+Pie Number of slices to send: Send
Read the JavaDocs on java.lang.Process

Note the critical point about consuming the standard out and standard err output streams. If you don't, it just sits there.

This has come up a LOT on this forum.

Bill
+Pie Number of slices to send: Send
Also you need to read this article from JavaWorld

regards,

Geo
+Pie Number of slices to send: Send
Try this...then read through what is going on...should help...


[ September 08, 2008: Message edited by: G Estes ]
Water! People swim in water! Even tiny ads swim in water:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2691 times.
Similar Threads
Probelom in Executing Process in Websphere 6.0.0.1
How do I deploy my application using a jar?
How to call a Java program in SQLServer?
run bat file within java
execute batch files in java
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 18:53:33.