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文件。
答案 0 :(得分:0)
String commands [] = new String [] {
"CMD.EXE",
"/C",
"RUNAS /profile /savecred /user:"
+ "administrator"
+ " " + "regedit.exe"
};
调用Runtime.getRuntime()EXEC(命令);