Runtime.getRuntime().exec("cmd /c .....");

解决方案 »

  1.   

    exec
    public Process exec(String command)
                 throws IOException
    Executes the specified string command in a separate process. 
    The command argument is parsed into tokens and then executed as a command in a separate process. The token parsing is done by a StringTokenizer created by the call:  new StringTokenizer(command)
     
    with no further modifications of the character categories. This method has exactly the same effect as exec(command, null). Parameters:
    command - a specified system command. 
    Returns:
    a Process object for managing the subprocess. 
    Throws: 
    SecurityException - if a security manager exists and its checkExec method doesn't allow creation of a subprocess. 
    IOException - if an I/O error occurs 
    NullPointerException - if command is null 
    IllegalArgumentException - if command is empty
    See Also:
    exec(java.lang.String, java.lang.String[]), SecurityManager.checkExec(java.lang.String)
      

  2.   

    java.lang.Runtime.exec(java.lang.String)
      

  3.   

    public class ReadingProcess {private Process process = null;
    private BufferedReader buffIn = null ;
    private String message = null ;
    private List msgList = null ;public List doProcess(String pProcess){
    Runtime runtime = Runtime.getRuntime();
    msgList = new ArrayList();try {
    process = runtime.exec(pProcess);
    buffIn = new BufferedReader( new InputStreamReader( process.getInputStream()));
    while((message=buffIn.readLine())!=null){
    msgList.add(message);
    }
    buffIn.close();
    } catch (IOException e) {
    e.printStackTrace();
    }
    return msgList;
    }
    }public class MainProc {    public static void main(String[] args) {ReadingProcess rp = new ReadingProcess();
             List list = rp.doProcess("cmd.exe /c dir");
        }
    }以前写的一个类,用来读取process返回信息用的,因为返回信息可能是多行,所以放在一个list中