Today I had some trouble to redirect the default and error output from a created process. So here is my final solution:
open System.Diagnostics
open System.Threading
// outputF: string -> unit
// errorF: string -> unit
let runProcess outputF errorF =
use p = new Process()
p.StartInfo.UseShellExecute <- false
// …
p.StartInfo.RedirectStandardOutput <- true
p.StartInfo.RedirectStandardError <- true
p.ErrorDataReceived.Add
(fun d –> if d.Data <> null then errorF d.Data)
p.OutputDataReceived.Add
(fun d –> if d.Data <> null then outputF d.Data)
p.Start() |> ignore
p.BeginErrorReadLine()
p.BeginOutputReadLine()
p.WaitForExit()
p.ExitCode