I’ve got a program that spawns two other proccesses using System.Diagnostics.Process. Their output is captured by the first program:
players[p.Key].StartInfo = new ProcessStartInfo
{
FileName = args[i],
RedirectStandardInput = true,
RedirectStandardOutput = true,
UseShellExecute = false
};
I’m trying to debug these sub-proccesses. Debug.WriteLine works from the main program, but it isn’t captured when called from within the sub-processes. How can I get it to work?
Is there a way to “redirect” that too? Or to open an output window in VS for the sub-proccesses?
You can can capture all the Debug.WriteLine output from every process with DbgView ( http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx ).
You can filter/highlight by process too, which might be helpful.
Actually, that probably won’t capture the process which VS is actually debugging, so you’ll get your top level process trace in VS and your other processes in DbgView, which might work out nicely.
Another potentially useful technique during development (or on systems where the ugly console window doesn’t matter) is to redirect the trace output to a console like this:
You can add a console to any application by calling AllocConsole(), which you’ll need to p/invoke, by adding the following declaration to your code:
See:
http://msdn.microsoft.com/en-us/library/system.diagnostics.consoletracelistener.aspx