我遇到了使C ++ exe和C#模块协同工作的问题。虽然我已经使用了stackoverflow线程Redirecting C++ console output to C#中描述的OutputDataReceived,但只有在C ++ exe终止后才能获得输出。以下就是我所拥有的,
private void Form1_Load(object sender, EventArgs ex)
{
Process process = new Process();
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.FileName = "C:\\path\\app.exe";
process.OutputDataReceived += Process_OutputDataReceived;
process.Start();
process.BeginOutputReadLine();
}
void Process_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
if(e.Data != null){
string s = e.Data.ToString();
Console.WriteLine(s);
}
}
有谁能让我知道我在这里缺少什么?
谢谢。