Java 调用系统命令,并打印出执行结果

来源:互联网 发布:淘宝第三方软件 编辑:程序博客网 时间:2024/04/25 13:13
java 调用系统命令并 打印出执行结果。
command 为一个字符串(String)
Process process = Runtime.getRuntime().exec (command);
            OutputStream testStream
= process.getOutputStream();
//            Integer.toOctalString(Integer.parseInt(testStream).intValue());
            InputStreamReader ir= new InputStreamReader(process.getInputStream());
            LineNumberReader input 
= new LineNumberReader (ir);

            String line;
            
while ((line = input.readLine ()) != null){
             System.out.println(line);