我已经看到了几个关于这个主题,但我没有得到我的工作。 我想要做的就是从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) –