想使用 java servlet 執行 echot.BAT 文件。我使用了以下代碼。Process croppingProcess = Runtime.getRuntime() .exec("C:Windows/system32/cmd /c echot.BAT", null, new File("C:restapi_bat/echot")); int processOutput = croppingProcess.waitFor(); if(processOutput == 0){ success = true; //do your work here }但得到錯誤"C:Windows/system32/cmd" (in directory "C:restapi_bat\echot"): CreateProcess error=267, 目錄名無效C:\restapi_bat 中的文件 echot.BAT注意:使用 tomcat 7
2 回答

月關寶盒
TA貢獻1772條經驗 獲得超5個贊
使用escape和Start,bat執行的解決方法如下
Process croppingProcess = Runtime.getRuntime()
.exec("C:\\Windows\\System32\\cmd.exe /C Start C:\\restapi_bat\\echot ");
int processOutput = croppingProcess.waitFor();
if(processOutput == 0){
success = true;
//do your work here
}
添加回答
舉報
0/150
提交
取消