title: Reading and writing to a command prompt console using VB.net
body: <p>I have asked a similar question elsewhere but perhaps I did not ask it the right way or I was not clear enough so I am asking again.</p>
  
  <p>This is where I want to get:</p>
  
  <ol>
  <li>Open a windows command prompt</li>
  <li>Run a DOS application through a dos command</li>
  <li>Read the returned text that is shown in the dos box and show it in a text box in my windows form. This needs to be repeated at regular intervals (say, every second) and the dos box should not be closed.</li>
  </ol>
  
  <p>I have been going round in circles trying to use the Process and StartInfo commands, but they only run the application and close the process right away. I need to keep the dos box open and keep reading any new text that is added to it by the dos application. I also came across this thread that seems to answer my problem, but it is to in C# and I could not convert it:</p>
  
  <p><a href="https://stackoverflow.com/questions/8892445/read-windows-command-prompt-stdout?rq=1">Read Windows Command Prompt STDOUT</a></p>
  
  <p>I did get to the part where I open the command prompt and get the application started, but I don't know how to read the data that it returns to the dos box console every now and then. I want to constantly check for changes so that I can act on them, perhaps using a timer control.</p>
  
  <p>Please help.</p>
  
  <p>Thanks!</p>
  
  <p>I ran the code that was kindly provided by Stevedog and used it like this:</p>
  
  <pre><code>  Private WithEvents _commandExecutor As New CommandExecutor()
  
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
      _commandExecutor.Execute("c:\progra~2\zbar\bin\zbarcam.exe", "")
    End Sub
  
    Private Sub _commandExecutor_OutputRead(ByVal output As String) Handles _commandExecutor.OutputRead
      txtResult.Text = output
    End Sub
  </code></pre>
  
  <p>But all I am getting is blank dos box. The zbarcam application runs properly because I can see the camera preview and I can also see it detecting QR Codes, but the text is not showing in the dos box and <code>_commandExecutor_OutputRead</code> sub is not being triggered unless I close the DOS box.</p>