【发布时间】:2014-01-20 03:44:24
【问题描述】:
我有一个 C# 应用程序 A,它调用另一个 C# 应用程序 B,它调用多个应用程序实例 C。
我想将应用程序 C 的输出重定向到应用程序 A 的输出。
我已经将应用程序B 的输出重定向到应用程序A 的输出。
现在,在应用程序B 的代码中,我正在重定向每个进程的输出,并将重定向的输出打印到控制台。不幸的是,由于某种原因,没有打印任何内容。
(我目前正在测试它而不使用应用程序A - 我只运行应用程序B)。
代码如下:
private void runSingleFile (string execFile, string commandArgs)
{
Process processToRun = new Process();
processToRun .StartInfo.FileName = execFile;
processToRun .StartInfo.Arguments = commandArgs;
processToRun .StartInfo.UseShellExecute = false;
processToRun .StartInfo.RedirectStandardOutput = true;
processToRun .OutputDataReceived += outputRedirection;
processToRun.Start();
Console.WriteLine("");
Thread.Sleep(100);
processToRun.BeginOutputReadLine();
}
private void outputRedirection(object sendingProcess, DataReceivedEventArgs outLine)
{
try
{
if (outLine.Data != null)
Console.WriteLine(outLine.Data);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return;
}
}
有什么想法吗?
【问题讨论】:
-
一些应用程序写入 StandardError 而不是 StandardOutput,您是否也尝试过重定向您的 StandardError?
-
我确定应用程序
C写入 StandardOutput,我写了它..无论如何,我现在尝试了 - 仍然没有。
标签: c# process output io-redirection