|
How to capture the output of an external program |
|
|
You can capture the output of an external program using the logic shown below:
import java.io.*;
public class CmdExec {
public CmdExec(String cmdline) {
try {
String line;
Process p = Runtime.getRuntime().exec(cmdline);
BufferedReader input =
new BufferedReader
(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
System.out.println(line);
}
input.close();
}
catch (Exception err) {
err.printStackTrace();
}
}
public static void main(String argv[]) {
new CmdExec("myprog.bat");
}
}
|
[myprog.bat]
echo hello world!
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.