无法从控制台进程获得输出

本文关键字:输出 进程 控制台 | 更新日期: 2023-09-27 18:13:59

此代码与ipconfig.exe一起工作得很好,但我的目标应用程序一无所获。

Process p = new Process();
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.FileName = "miner.exe";
p.StartInfo.Arguments = command;
p.EnableRaisingEvents = true;
p.OutputDataReceived += OutputDataReceived;
p.ErrorDataReceived += ErrorDataReceived;
p.Start();
p.BeginOutputReadLine();
p.StandardInput.Close();

谁能告诉什么可能是错的,我能做什么?目标应用程序是用c++编写的,我认为使用printf输出。在论坛上,我看到有人说他不能让这个应用程序与linux中的管道工作

无法从控制台进程获得输出

代码看起来不错。

如果process不向标准输出输出任何内容,您将无法捕获任何内容。

你可以通过在Windows上使用现有的输出重定向或管道输出到其他程序来验证它是程序的行为而不是代码中的错误。Windows/*nix -

tool.exe > output.txt  
tool.exe | more