我試圖運行java應用程序中的簡單提示命令。無法在Java程序中執行提示命令
無論我嘗試什麼,我alwasy收到CreateProcess error=2
。
這是我的代碼:
File f = new File("C:/Users/my/path/to/the/executable/");
String[] commands = { "text.txt", "--command1" /* others commands */ };
// omitting try/catch
Process p = Runtime.getRuntime().exec("myprogram.exe", commands, f);
p.waitFor();
// other code
的exe採用作爲第一個參數爲.txt文件,然後它需要正常的命令作爲--command1。
我怎樣才能得到這個工作?提前致謝!
你有什麼錯誤? – talex
@talex,更具體地說是: Java.io.IOException:無法運行程序「myprogram.exe」(在目錄「/ thedirectory」中):error = 2,沒有這樣的文件或目錄 – Matteo