How Direct Runtime.getRuntime().exec output to Console window ??
Jim Otte
Greenhorn
Joined: Feb 20, 2002
Posts: 6
posted
0
Problem: I want to execute .bat in separate console window with output to that console window. Solution 1: String command = "cmd /c E:\\batFiles\\MyBat.bat"; Process pc = Runtime.getRuntime().exec(command);
Does not show output at all Solution 2: String command = "cmd /c E:\\batFiles\\MyBat.bat"; Process pc = Runtime.getRuntime().exec(command); BufferedReader in = new BufferedReader(new InputStreamReader(pc.getInputStream())); String response; while ((response = in.readLine()) != null) { System.out.println("-" + response); } Prints to std.out- not to new dos window- Question- what needed to direct inputStream to new console window??? Thanks
Jim Otte
Greenhorn
Joined: Feb 20, 2002
Posts: 6
posted
0
Found to be: String command = "cmd /c start E:\\batFiles\\MyBat.bat"; Process pc = Runtime.getRuntime().exec(command);
Sandeep Lakshmipathy
Ranch Hand
Joined: Mar 05, 2002
Posts: 31
posted
0
A more generic approach would be some thing like this //......... Process p = Runtime.getRuntime().exec(cmd); if(p.waitFor() != 0) System.out.println(getOutAndErrStream(p)); // private String getOutAndErrStream(Process p){