Skip to main content


2 replies [Last post]
Joined: 2007-08-30

Hello all.
I'm trying to launch an external "c:\\go.bat" command from a Java class but it doesn't work. I am trying with a simple command like the following.

go.bat =
C:\\j2sdk1.4.2_01\\bin\\java -classpath c:\\trial MyWindow
From a windows console it runs (a JFrame is shown) but from Java it doesn't produce any result!

I tried to run the external command line in many ways...
1) Process p = Runtime.getRuntime().exec("c:\\go.bat");
2) Process p = Runtime.getRuntime().exec(new String[] {"cmd.exe", "/C", "c:\\go.bat"});
I am in Windows 2000 Professional. Can anybody help me please?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2006-05-30
Joined: 2003-07-17


May the troule be that a *.bat file is executed a litttle different than other types of executable files?

Try if

Runtime.getRuntime().exec("C:\\j2sdk1.4.2_01\\bin\\java -classpath c:\\trial MyWindow");

gives the desired result.

If that is the case, you might read that line from your bat file and execute it directly. (Remains a problem when your bat file consists of multiple lines ofcourse).

Hope this helps.