java面试题

当前位置: 面试问题网 > java面试题 > 为什么Runtime.exec(“ls”)没有任何输出?

为什么Runtime.exec(“ls”)没有任何输出?

调用Runtime.exec方法将产生一个本地的进程,并返回一个Process子类的实例,该实例可用于控制进程或取得进程的相关信息。由于调用Runtime.exec方法所创建的子进程没有自己的终端或控制台,因此该子进程的标准IO(如stdin,stdou,stderr)都通过Process.getOutputStream(),Process.getInputStream(),Process.getErrorStream()方法重定向给它的父进程了。用户需要用这些stream来向子进程输入数据或获取子进程的输出。所以正确执行Runtime.exec(“ls”)的例程如下:
   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());
   }

【为什么Runtime.exec(“ls”)没有任何输出?】相关文章

1. 为什么Runtime.exec(“ls”)没有任何输出?

2. 若通过ObjectOutputStream向一个文件中多次以追加方式写入object,为什么用ObjectInputStream读取这些object时会产生StreamCorruptedExcepti

3. 软件测试LoadRunner面试题:If you want to stop the execution of your script on error, how do you do that?

4. 简述你对Statement,PreparedStatement,CallableStatement的理解

5. 你常见到的runtime exception

6. 软件测试LoadRunner面试题:Explain the following functions: – lr_debug_message

7. 我们在web应用开发过程中经常遇到输出某种编码的字符,如iso8859-1等,如何输出一个某种编码的字符串?

8. Java 中访问数据库的步骤?Statement 和PreparedStatement 之间的区别?

9. 既然说Ruby中一切都是对象,那么Ruby中类也是对象吗

10. 软件测试LoadRunner面试题: Types of Goals in Goal-Oriented Scenario

本文来源:https://www.mianshiwenti.com/a12573.html

点击展开全部

《为什么Runtime.exec(“ls”)没有任何输出?》

将本文的Word文档下载到电脑,方便收藏和打印

推荐程度:

进入下载页面

﹝为什么Runtime.exec(“ls”)没有任何输出?﹞相关内容

「为什么Runtime.exec(“ls”)没有任何输出?」相关专题

其它栏目

也许您还喜欢