interacting with a process
Posted on 2010-09-06
Hello, I am attempting to interact with a process that I launch. I need to monitor its output and enter key strokes in response to the output from the process. I cannot wait for the process to exit before seeing and responding to its output. Here is a simple example of what I am talking about as what you would see if using a cmd window:
C:\STMFlashLoader.exe -c --pn 17 --br 115200
Opening Port [OK]
Press any key to continue...
I have code working that allows me to monitor the output, but am unable to "send keys" with stream or sendkeys. I would like a structure such that I can monitor the output and when I see certain strings, respond by sending an appropriate string back to the process, and continue to monitor and again, send an appropriate string until the process exits or I terminate the process.
Here is the code I have working at this point
Dim start_info As New ProcessStartInfo("C:\Program Files\STMicroelectronics\Software\Flash Loader Demonstrator\STMFlashLoader.exe")
start_info.Arguments = "-c --pn 17 --br 115200"
start_info.UseShellExecute = False
start_info.CreateNoWindow = True
start_info.RedirectStandardOutput = True
start_info.RedirectStandardError = True
' Make the process and set its start information.
Dim proc As New Process()
proc.StartInfo = start_info
' Start the process.
' Attach to stdout and stderr.
Dim std_out As StreamReader = proc.StandardOutput()
Dim std_err As StreamReader = proc.StandardError()
' Display the results.
txtStdout.Text = std_out.ReadToEnd()
txtStderr.Text = std_err.ReadToEnd()
' Clean up.