This article addresses why runtime.exec ("ls") does not have any output to answer as follows:
calling the Runtime.exec method results in a local process and returns an instance of a process subclass that can be used to control the process or get information about the process. Because the child process created by calling the Runtime.exec method does not have its own terminal or console, So the standard IO of the subprocess (e.g. Stdin,stdou,stderr) is passed through Process.getoutputstream (), Process.getinputstream (), Process.geterrorstream () Method is redirected to its parent process. The user needs to use these streams to enter data into the child process or to get the output of the child process. So the proper execution of the runtime.exec ("ls") routine is as follows:
Try
{
process = Runtime.getruntime (). exec (command);
InputStreamReader Ir=newinputstreamreader (Process.getinputstream ());
LineNumberReader input = new LineNumberReader (IR);
String Line;
While (line = Input.readline ()) = null)
System.out.println (line);
}
catch (Java.io.IOException e) {
System.err.println ("IOException" + e.getmessage ());
}
This article is from the Java Learning Video tutorial blog, so be sure to keep this source http://10239772.blog.51cto.com/10229772/1653295
Why Runtime.exec ("ls") does not have any output _java basic tutorial