在我的eclipse項目中,我試圖運行系統命令,我已經將它們收集在一個bash中並將它放在我的項目文件夾中。在java程序中運行批處理腳本
Java代碼的部分是:
public static int exportDBMainData(String DBName, String UserName,
String Password, String FilePath) {
// First
String executeCmd = GraphEditor.class
.getResource("/src/sau/se/editor/recover/semapExport.bat")
+ UserName + " " + Password + " " + DBName + " " + FilePath;
Process runtimeProcess = null;
try {
runtimeProcess = Runtime.getRuntime().exec(executeCmd);
} catch (IOException e1) {
e1.printStackTrace();
}
int processComplete1 = -1;
try {
processComplete1 = runtimeProcess.waitFor();
} catch (InterruptedException e1) {
e1.printStackTrace();
}
return processComplete1;
}
當我運行該應用程序我得到這個錯誤:
java.io.IOException: Cannot run program "nullroot": 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)
我在做什麼錯?
UPDATE 我部分解決了這一問題,現在我得到:
java.io.IOException: Cannot run program "file:/F:/SEMAP_PROJECT/PHASE_1/ECLIPSE_KEPLER/Workspace/SeMap_Recover1.0/bin/sau/se/editor/recover/semapExport.bat": CreateProcess error=2, The system cannot find the file specified
你說這是一個bash腳本,但它有一個.bat擴展名... – SeriousBusiness
我想保證你的getResource()調用有問題。嘗試打印'executeCmd'以確保它是正確的。 – azurefrog