无法捕获过程标准输出?

时间:2014-02-14 23:10:33

标签: c#

我正在启动一个进程并尝试读取StdOut ...我非常熟悉启动进程,重定向和捕获输出的常规方法。

但是,我遇到了一个应用程序,我可以在命令提示符下手动启动并查看控制台中的输出,但不会在StdOut或StdErr流上提供任何输出。我首先尝试启动cmd.exe并且能够从cmd.exe捕获输出,但是当以这种方式启动时也不能捕获此过程。

更清楚一点,当我手动运行app.exe时,我在控制台上看到了这个:

尝试连接到VP

尝试连接到VP

直接从System.Diagnostics.Process启动时:

[空白]

当我通过cmd.exe从System.Diagnostics.Process启动它时:

Microsoft Windows [Version 6.1.7601]

版权所有(c)2009 Microsoft Corporation。保留所有权利。

同样,我用来做这个的类运行很多进程,只有一个问题是使用这个app.exe获取输出,所以这不是“嘿可能尝试重定向标准输出”类型的问题。我知道这适用于我的实施。

想法?我之前从未遇到过这样的问题。当手动运行时,进程如何在控制台窗口上放置一些东西,而不是在通过Process对象运行时?

这是我的代码:

process = new Process();
process.StartInfo.FileName = f.FullName;
process.StartInfo.Arguments = arguments;
process.StartInfo.WorkingDirectory = workingDir;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardInput = true;
process.OutputDataReceived += p_OutputDataReceived;
process.ErrorDataReceived += p_ErrorDataReceived;
if (!process.Start())
{
    throw new Exception("Failed to start [" + f.Name + "]. Exit code " + process.ExitCode);
}
process.BeginOutputReadLine();
process.BeginErrorReadLine();

processRunning = true;

process.WaitForExit();

exitCode = process.ExitCode;

0 个答案:

没有答案
相关问题