The following code hangs in the call to WaitForExit at the end. It terminates cleanly if I remove the 1 second long sleep. Could someone please tell me what to do so the process would die shortly after I call Kill() on it? Many thanks.
let processStartInfo = System.Diagnostics.ProcessStartInfo("c:/cygwin/bin/bash.exe", "-c yes")
processStartInfo.CreateNoWindow <- true
processStartInfo.UseShellExecute <- false
processStartInfo.RedirectStandardOutput <- true
processStartInfo.RedirectStandardInput <- false
processStartInfo.RedirectStandardError <- true
use proc = new System.Diagnostics.Process ()
proc.StartInfo <- processStartInfo
let f _ = ()
proc.OutputDataReceived.Add f
proc.ErrorDataReceived.Add f
if not (proc.Start()) then
failwithf "Could not start"
proc.BeginErrorReadLine ()
proc.BeginOutputReadLine ()
// the process terminates fine without this
System.Threading.Thread.Sleep (1000)
printf "Waiting to die"
proc.Kill () // this does not seem to work
proc.CancelOutputRead ()
proc.CancelErrorRead ()
proc.WaitForExit() // execution gets stuck here, apparently forever