I'm trying to run a .bat file and get the output. I can run it but I can't get the results in Java:
String cmd = "cmd /c start C:\\workspace\\temp.bat";
Runtime r = Runtime.getRuntime();
Process pr = r.exec(cmd);
BufferedReader stdInput = new BufferedReader(
new InputStreamReader( pr.getInputStream() ));
String s ;
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
The result is null
. No idea why I get this. Note that I'm using Windows 7.
exec
and build theProcess
using aProcessBuilder
. Also break aString arg
intoString[] args
to account for arguments which themselves contain spaces. – Kestrel