I have this method to write a line to a visual debug area in an ASP.NET application:
private void WriteDebug(string s)
{
debugBox.Text = debugBox.Text + "\r\n" + s;
}
I call that method when running command line processes:
private void RunCommand(string command)
{
WriteDebug("Command initiated\r\n\t" + command);
var process = new Process()
{
StartInfo = new ProcessStartInfo("cmd")
{
UseShellExecute = false,
RedirectStandardInput = true,
RedirectStandardOutput = true,
CreateNoWindow = true,
Arguments = String.Format("/c \"{0}\"", command),
}
};
process.OutputDataReceived += (s, e) => WriteDebug(e.Data);
process.Start();
process.BeginOutputReadLine();
}
Even though the commands are successful, debugBox never shows any of the output. I'm probably using OutputDataReceived wrong but I'm not sure how. Any help?