title: Run multiple cmd commands from java
body: <p>I want to run multiple cmd commands succesively from java code one after the other. </p>
  
  <p>I want to use this one command line application which creates ssh connection and I want to run multiple commands succesively like in a normal command prompt window without actually closing the session. Most answers I found about running cmd command from java talked about running a single command and then stopping. Like the answer in this question:</p>
  
  <p><a href="https://stackoverflow.com/questions/15464111/run-cmd-commands-through-java">Run cmd commands through java</a></p>
  
  <p>I need to redirect the output of my commands to the console and also get the new commands as inputs from the console. Sort of like emulating a cmd window using java code. And then end the cmd session as necessary and continue with the rest of the program.</p>
  
  <p>EDIT:</p>
  
  <p>I am trying to run a command line implementation of <code>Putty</code> called <code>plink</code>. It is used as  </p>
  
  <p><code>plink -ssh &lt;hostname&gt; -P &lt;port&gt; -l &lt;username&gt; -pw &lt;password&gt;</code> </p>
  
  <p>in cmd and then the linux terminal of the host is emulated on the cmd. After that you run all the usual linux commands like <code>ls</code> straight into the command prompt. So I want to emulate that without closing the supposedly emulated command prompt of my java code.</p>