Redirect and parse in realtime stdout of an long running process in vb.net
- by Richard
Hello there,
This code executes "handbrakecli" (a command line application) and places the output into a string:
Dim p As Process = New Process
p.StartInfo.FileName = "handbrakecli"
p.StartInfo.Arguments = "-i [source] -o [destination]"
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardOutput = True
p.Start
Dim output As String = p.StandardOutput.ReadToEnd
p.WaitForExit
The problem is that this can take up to 20 minutes to complete during which nothing will be reported back to the user. Once it's completed, they'll see all the output from the application which includes progress details. Not very useful.
Therefore I'm trying to find a sample that shows the best way to:
Start an external application (hidden)
Monitor its output periodically as it displays information about it's progress (so I can extract this and present a nice percentage bar to the user)
Determine when the external application has finished (so I can't continue with my own applications execution)
Kill the external application if necessary and detect when this has happened (so that if the user hits "cancel", I get take the appropriate steps)
Does anyone have any recommended code snippets?