运行exe时运行runtime.getRuntime()。exec()异常

时间:2014-02-16 14:22:58

标签: java ioexception runtime.exec

import java.io.IOException;

public class RunExternalExe {
    public static void main(String args[]) {
        try {
            Process p = Runtime.getRuntime().exec("E:\\aaaa.exe, E:\\aaaaa.msi, E:\\aaaaa.mst");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.getMessage();
            System.out.println("\n\n\n");
            e.printStackTrace();
        }
    }
}

现在我得到了这个例外。

java.io.IOException: Cannot run program "E:\aaaaaa.exe,E:\aaaaaaa.msi,E:\aaaaaa.mst": CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessBuilder.start(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at csvwriter.RunExternalExe.main(RunExternalExe.java:8)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.<init>(Unknown Source)
    at java.lang.ProcessImpl.start(Unknown Source)
    ... 5 more

但命令E:\aaaaa.exe,E:\aaaaa.msi,E:\aaaaa.mst正常工作。

exe文件是在发布模式下构建的cpp文件。

1 个答案:

答案 0 :(得分:0)

             String  commands [] = new String [] {
           "CMD.EXE",
           "/C",
          "RUNAS /profile  /savecred /user:"
          + "administrator"
          + " " + "regedit.exe"
          };

调用Runtime.getRuntime()EXEC(命令);