当前位置: 代码迷 >> Java相关 >> Runtime.getRuntime().exec()执行多命令问题,求解答
  详细解决方案

Runtime.getRuntime().exec()执行多命令问题,求解答

热度:1889   发布时间:2012-03-31 17:12:51.0
Runtime.getRuntime().exec()执行多命令问题,求解答
先上代码
package hardwarelistenforsolaris;

import java.io.*;
import java.util.Scanner;


public class HardwareListenForSolaris {

    public static void main(String[] args) throws FileNotFoundException, IOException {
        // TODO code application logic here
        PrintStream ps = null;
        FileInputStream fis = null;
        try
        {
            ps = new PrintStream(new FileOutputStream("test.txt"));
            String[] cmd = {"cmd.exe ","/c","ipconfig","netstat"," > F:\\ababab.txt"};
//          Process p=  Runtime.getRuntime().exec("cmd.exe /c ipconfig > F:\\more.txt");
            Process p=  Runtime.getRuntime().exec(cmd);

        }  
        catch(IOException ex)
        {
            ex.printStackTrace();
        }
        finally
        {
            if(ps != null)
            {
                ps.close();
            }
        }
    }
}


我想要的结果是在一个进程里面启动cmd 然后输入ipconfig 和netstat之类的命令 并把输出打印到一个txt里面 现在出了不知道什么错误的错误 求解答 谢谢
搜索更多相关的解决方案: class  package  public  import  

----------------解决方案--------------------------------------------------------
没一个人会吗
----------------解决方案--------------------------------------------------------
  相关解决方案