title: VB.Net Process running a non-batch program
body: <p>Maybe I have the wrong approach here. I need to run a program to configure a piece of equipment. This has to run in the "background" and its basically a non batch program so it takes constant input in a loop from the user. I wrote the below code to launch the process and attempt to read/write from it but it doesn't work. I know the program is launching correctly, but I get no output until the program is killed. Am I doing something incorrectly?    </p>
  
  <pre><code>Dim proc As Process
  Dim prompt As String
  
  
  Public Sub New()
      proc = New Process()
  
      AddHandler proc.OutputDataReceived, AddressOf CallbackDataReceived
      AddHandler proc.ErrorDataReceived, AddressOf CallbackErrorDataReceived
  
      prompt = ""
  
      Dim pi As ProcessStartInfo = New ProcessStartInfo()
      pi.UseShellExecute = False
      pi.FileName = "processname and location"
      pi.RedirectStandardInput = True
      pi.RedirectStandardOutput = True
      pi.RedirectStandardError = True
      pi.CreateNoWindow = True
      proc.StartInfo = pi
      proc.EnableRaisingEvents = True
      StartProcess()
  
      proc.BeginOutputReadLine()
  End Sub
  
  Public Sub StartProcess()
      proc.Start()
  End Sub
  
  Private Sub CallbackDataReceived(sender As Object, args As System.Diagnostics.DataReceivedEventArgs)
      If Not String.IsNullOrEmpty(args.Data) Then
          Console.Write(args.Data)
      End If
  End Sub
  
  Private Sub CallbackErrorDataReceived(sender As Object, args As System.Diagnostics.DataReceivedEventArgs)
      If Not String.IsNullOrEmpty(args.Data) Then
          Console.Write(args.Data)
      End If
  End Sub
  </code></pre>