Interacting with another process Java
<p>I am trying to interact with another process in Java. It goes like this... </p>

<pre><code>Runtime rt;
Process pr=rt.exec("cmd");
</code></pre>

<p>then I send some commands to the process using... </p>

<pre><code>BufferedReader processOutput = new BufferedReader(new InputStreamReader(pr.getInputStream()));
BufferedWriter processInput = new BufferedWriter(new OutputStreamWriter(pr.getOutputStream()));

processInput.write("gdb");
processInput.flush();
</code></pre>

<p>I don't care about the output for now.. so I try to ignore it using.. </p>

<pre><code>while(processOutput.readLine() != null);
</code></pre>

<p>but this loops hangs forever. I know this is because process is still running and doesn't sends a null. I don't want to terminate it now. I have to send commands based on user Input and then get the output.. </p>

<p>How to do this? In other words I want to flush the Process output stream or ignore it after executing some commands and read it only when I want to.</p>
