我已經看到了幾個關於這個主題,但我沒有得到我的工作。 我想要做的就是從java程序打開cmd.exe。如何在java中打開cmd.exe
notepad.exe打開罰款。
的問題是,cmd.exe的dosent開放,代碼編譯好,並沒有錯誤
這裏是我的代碼:
public class CMD {
public static void main(String[] args) {
//Trying some variants how to start.
//String cmd = "C:\\WINDOWS\\system32\\cmd.exe";
//String[] cmd = {"C:\\WINDOWS\\system32\\cmd.exe","start"};
String[] cmd = {"C:\\WINDOWS\\system32\\cmd.exe","/c","start"};
// notepad works fine
//String notepad = "C:\\WINDOWS\\system32\\notepad.exe";
try {
Runtime runtime = Runtime.getRuntime();
//Process p = runtime.exec(notepad);
Process p = runtime.exec(cmd);
}
catch (java.io.IOException exception) {
System.out.println("Caught IOException: " + exception.getMessage());
}
}
}
你的問題不能被發現。請重試。 – Maroun
有什麼問題?錯誤訊息?你有什麼嘗試? –
可能重複[如何打開命令提示符並使用Java插入命令?](http://stackoverflow.com/questions/4688123/how-to-open-the-command-prompt-and-insert-commands-using -java) –