Assume the following code:
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()
I create a process and exit the main application. The process is still 开发者_JS百科running (as it should) but it stops redirecting the standard output. Is there any way how to continue writing the standard output to the file even after the main application exits?
PS: I have to exit the main application and cannot wait for the process to finish
PPS: I would like to do a similar thing for the standard error outputI think desco's answer may work if RedirectStandardOutput
is false. The output isn't being written to the file after your process exits because the OutputDataReceived
event handler no longer exists. If possible, I'd recommend passing the output file path to your program (assume no path means write to stdout). With that in place it should be easy to do what you're trying to do.
can you perform redirect by starting process with proper command line: Redirect stdout and stderr to a single file in dos?
精彩评论