Set System.setOut(); to Command Prompt

I want to set output stream to the Command prompt like this:

Process p = Runtime.getRuntime()
          .exec("C:\\Windows\\System32\\cmd.exe /c start cls");

System.setOut(new PrintStream(p.getOutputStream()));

but it is not working, why ?

First of all keep the reference id of System.out to a PrintStream type variable. like:

PrintStream ps=System.out;


now change your stream to other OutputStream…

and again when you want to redirect your OutputStream to Console, use the previous saved variable.

System.setOut(ps);

//