【发布时间】:2016-03-29 11:40:52
【问题描述】:
我正在执行一个 exe 文件,其中包含我的 c# winform 中的一些 c 代码,但只有在完全执行 exe 后才能获得 c 代码的完整输出。我希望 exe 将其输出同步传递到我的 winform(实时逐行)。
var proc = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "background.exe",
Arguments = command,
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};
proc.Start();
while (!proc.StandardOutput.EndOfStream)
{
ConsoleWindow.AppendText(proc.StandardOutput.ReadLine());
ConsoleWindow.AppendText(Environment.NewLine);
}
【问题讨论】:
-
some c code是什么意思?除非正在执行的 process 将其放在那里,否则不会将文本写入输出。你应该检查background.exe的代码。并确保background.exe实际上是一个已编译的二进制可执行文件,而不仅仅是具有不同扩展名的 C 文件 -
检查了所有的代码示例,他们只有在过程完成后才读取输出。