Start CMD by using ProcessBuilder

匆匆过客 提交于 2019-11-27 09:16:34
Kazekage Gaara

You need to use the start command. Actually, even I don't see a new command prompt popping up, but you can check that a new cmd.exe is definitely started using your task manager.

ProcessBuilder pb = new ProcessBuilder("cmd.exe", "/C", "start");

Though, the same functionality can be achieved using Runtime.exec(), and this actually pops up a new command prompt.

Runtime.getRuntime().exec("cmd.exe /C start");
Guilherme

To use it with ProcessBuilder you must separate the commands like this:

final List<String> commands = new ArrayList<String>();                

commands.add("cmd.exe");
commands.add("/C");
commands.add("start");
ProcessBuilder pb = new ProcessBuilder(commands);
pb.start();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!