主應用程序退出假定以下代碼:RedirectStandardOutput當使用F#
let sw = new StreamWriter("out.txt", false)
sw.AutoFlush <- true
let proc = new Process()
proc.StartInfo.FileName <- path
proc.StartInfo.RedirectStandardOutput <- true
proc.StartInfo.UseShellExecute <- false
proc.OutputDataReceived.Add(fun b -> sw.WriteLine b.Data)
proc.Start() |> ignore
proc.BeginOutputReadLine()
我創建一個進程,並退出主應用程序。該進程仍在運行(它應該),但它會停止重定向標準輸出。即使主應用程序退出後,如何繼續將標準輸出寫入文件,還有什麼辦法嗎?
PS:我不得不退出主應用程序,不能等待進程結束
PPS:我願做類似的事情爲標準錯誤輸出
謝謝,好點。有時我看不到最簡單明顯的解決方法:) – 2011-06-15 05:12:46