Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

running batch files

Status
Not open for further replies.

mar10

Programmer
Sep 18, 2001
26
0
0
NL
Hi folks

I'm trying to run a batch file (*.bat) from my java source code.

When it's time to start the batch. The command prompt is opened and there the application stays. It doesn't do anything.

The title of the prompt is and stays c:\winnt\...\cmd.exe

Can anyone help me

p.s. When running the batch in normal command line mode, it's working fine.
 
Hi,
As far as i know the parameter that u pass to the exec method of the Runtime class has to be an .exe for the run time to execute it ,it cannot execute .bat files. I dont know if there is a workaround to it.


Cheers,
Reddy316
 
Hi,

You can use Runtime.exec() to execute batch files just like any other executable files. I'm not sure what kind of bat file you are going to execute (what you except it to do), but this example below works fine. It runs a batch file that starts a java application named test.

a simple batch file looks like this:
java test

...and it is executed like this:
Process p = Runtime.getRuntime().exec("testBatch.bat");

An above example won't start a new dos-promt window. If you want the program to do this just do the following changes:

Process p = Runtime.getRuntime().exec("cmd.exe /c START testBatch.bat");
 
Hi Folks

Problem solved

I had to capture the output stream of the batch file and put it in the output stream of java, that was the only trouble
 
Hi Vepo,
Hey thanx for the information man. That was really helpful.

Cheers,
Reddy316
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top