Java starts a new cmd.exe and gets the output stream

I am trying to create a new console in java and get the ouput stream.

I tried this way:

Process p = Runtime.getRuntime().exec("cmd.exe /c start");
BufferedWriter out = new BufferedWriter( new OutputStreamWriter(
                                         p.getOutputStream()));

the console appears, but I can not write something in the stream!

Another way:

Process p = Runtime.getRuntime().exec("cmd.exe");
  BufferedWriter out = new BufferedWriter(new OutputStreamWriter(
               p.getOutputStream()));

This time I can write to the stream, but the console does not multiply!

I lack knowledge: /

Thanks in advance.

+4
source share
1 answer

The first time you started cmd, and it started another process, which you also do not have access to. Do not use this method if you need an input / output stream.

. . . , "cd foo\n", "dir\n". , , . .

, .

0

Source: https://habr.com/ru/post/1584809/


All Articles