我有这种方法将一行写入ASP.NET应用程序中的可视调试区域:
private void WriteDebug(string s)
{
debugBox.Text = debugBox.Text + "\r\n" + s;
}
我在运行命令行进程时调用该方法:
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();
}
即使命令成功,debugBox也不会显示任何输出。我可能使用OutputDataReceived错误,但我不知道如何。有什么帮助吗?