I'm writing a class in Java which will be calling a Windows batch file. When I run this class, the batch file is getting opened and getting closed. How can I make the batch file continue to run after the Java program terminates?
A:
You are probably calling the batch with cmd /c batch.cmd
. If you use /k
instead of /c
the window will stay open after the batch ran.
Joey
2009-06-22 12:07:08
+1
A:
See this article for how to use Runtime.exec properly.
You probably need to start a new command line window:
Runtime rt = Runtime.getRuntime();
String[] commandArgs = new String[]{"cmd", "/C", "start", "c:\\test.bat" };
Process proc = rt.exec(commandArgs);
kgiannakakis
2009-06-22 12:16:04