|
How to read output from a Command execution |
|
|
This Java tip illustrates a method of reading an output from a command execution. Developer
after executing the command from the code may use this tip to read the output. This output
may then be further used in the code for various purposes.
try {
// Execute a command
String command = "ls";
Process child = Runtime.getRuntime().exec(command);
// Read from an input stream
InputStream in = child.getInputStream();
int c;
while ((c = in.read()) != -1) {
process((char)c);
}
in.close();
} catch (IOException e) {
}
|
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.