Show the CMD window with Java

2019-02-19 17:19发布

I'm using this code to launch a .cmd file:

try {
            String line;
            Process p = Runtime.getRuntime().exec(myPath + "\\punchRender.cmd");
            BufferedReader input =
                    new BufferedReader(new InputStreamReader(p.getInputStream()));
            while ((line = input.readLine()) != null) {
                System.out.println(line);
            }
            input.close();
        } catch (Exception err) {
            err.printStackTrace();
        }

It works fine, but I want to actually see the cmd.exe window running. How can I make it show? Any help would be greatly appreciated!

1条回答
一纸荒年 Trace。
2楼-- · 2019-02-19 17:34

Instead of running your path, try actually running cmd.exe but using the build in start command to launch a new command window. You can see the full set of command line arguments by entering the following at a command prompt:

cmd/?
start/?

in your case, you probably want to execute something like the command:

cmd /c start c:\path\to\punchRender.cmd
查看更多
登录 后发表回答