I have the following situation:
Application1 starts Application2 via Process.Start and redirects its standard output
Application2 starts a 3rd process (external application), also via Process.Start and redirects its standard output
This 3rd process hangs when Application2 redirects its standard output.
The source code of Application1 looks like this:
The source code of Application2 looks like this:
If I change Application2 so it doesn't redirect standard output, the 3rd process does not hang. So it appears to be some kind of dead-lock with nested processes that both redirect the standard output of their child-process.
Application1 starts Application2 via Process.Start and redirects its standard output
Application2 starts a 3rd process (external application), also via Process.Start and redirects its standard output
This 3rd process hangs when Application2 redirects its standard output.
The source code of Application1 looks like this:
ProcessStartInfo lStartInfo = new ProcessStartInfo(path, args); | |
lStartInfo.UseShellExecute = false; | |
lStartInfo.CreateNoWindow = true; | |
lStartInfo.RedirectStandardInput = true; | |
lStartInfo.RedirectStandardOutput = true; | |
lStartInfo.RedirectStandardError = true; | |
fProcess = new Process(); | |
fProcess.StartInfo = lStartInfo; | |
fProcess.EnableRaisingEvents = true; | |
fProcess.OutputDataReceived += delegate(object sender, DataReceivedEventArgs e) | |
{ | |
if (!string.IsNullOrEmpty(e.Data)) | |
this.EventLog.WriteEntry(e.Data, EventLogEntryType.Information); | |
}; | |
fProcess.ErrorDataReceived += delegate(object sender, DataReceivedEventArgs e) | |
{ | |
if (!string.IsNullOrEmpty(e.Data)) | |
this.EventLog.WriteEntry(e.Data, EventLogEntryType.Error); | |
}; | |
fProcess.Start(); | |
fProcess.BeginOutputReadLine(); | |
fProcess.BeginErrorReadLine(); |
The source code of Application2 looks like this:
ProcessStartInfo lStartInfo = new ProcessStartInfo(path, args); | |
lStartInfo.UseShellExecute = false; | |
lStartInfo.CreateNoWindow = true; | |
lStartInfo.RedirectStandardOutput = true; | |
lStartInfo.RedirectStandardError = true; | |
using(Process lProcess = new Process()) | |
{ | |
lProcess.StartInfo = lStartInfo; | |
lProcess.EnableRaisingEvents = true; | |
lProcess.OutputDataReceived += delegate(object sender, DataReceivedEventArgs e) | |
{ | |
if (!string.IsNullOrEmpty(e.Data)) | |
fStringBuilderLog.AppendLine(e.Data); | |
}; | |
lProcess.ErrorDataReceived += delegate(object sender, DataReceivedEventArgs e) | |
{ | |
if (!string.IsNullOrEmpty(e.Data)) | |
fStringBuilderLog.AppendLine(e.Data); | |
}; | |
lProcess.Start(); | |
lProcess.BeginOutputReadLine(); | |
lProcess.BeginErrorReadLine(); | |
lProcess.WaitForExit(); | |
} |
If I change Application2 so it doesn't redirect standard output, the 3rd process does not hang. So it appears to be some kind of dead-lock with nested processes that both redirect the standard output of their child-process.