【发布时间】:2014-08-21 00:05:14
【问题描述】:
在我的 eclipse 项目中,我正在尝试运行系统命令,我已将它们收集在 bash 中并将其放入我的项目文件夹中。
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)
我做错了什么?
更新 我解决了部分问题,现在我得到了:
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 扩展名......
-
我敢打赌你的
getResource()电话有问题。尝试打印出executeCmd以确保它是正确的。
标签: java eclipse bash resources command