• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not able to call a bat file from JAVA

 
Praveen Kumar Jayaram
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Spoor
Sheriff
Pie
Posts: 20494
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Steve Fahlbusch
Bartender
Posts: 602
7
Mac OS X Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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???
 
Joe Ess
Bartender
Posts: 9256
9
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13055
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Geo Joseph
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also you need to read this article from JavaWorld

regards,

Geo
 
G Estes
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this...then read through what is going on...should help...


[ September 08, 2008: Message edited by: G Estes ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic