我正尝试通过java执行'VACUUM VERBOSE'命令。
这是我的代码
public void executeCommand()
{
String cmd1= "cmd.exe /c start";
String location="C:\\PROGRA~1\\PostgreSQL\\8.3\\bin\\";
String postgresCommand="psql -h localhost -U postgres -d postgres";
String autoVaccum="-c \"vacuum verbose\"";
String []actualCmd={cmd1,location,postgresCommand,autoVaccum};
Process process=null;
try {
process = Runtime.getRuntime().exec(actualCmd);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
MyTest test= new MyTest();
test.executeCommand();
}但我得到了异常
java.io.IOException: Cannot run program "cmd.exe /c start": 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 MyTest.executeCommand(MyTest.java:36)
at MyTest.main(MyTest.java:48)
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.(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 5 more当我直接在Start-> Run窗口中直接输入上面的字符串时,它会成功执行
例如。
cmd.exe / C start C:\ PROGRA~1 / PostgreSQL / 8.3 / bin / psql -h localhost -U postgres -d postgres -c“vacuum verbose”
任何人都可以知道上述程序中究竟发生了什么问题吗?