感謝man.That工作就像一個魅力。
我正在使用setbuf設置緩衝區爲空。
真的很感謝所有你guyz的努力。
其他guyz的信息,這是我的c#代碼,它可以在互聯網論壇上也可以。
string command = @"Output.exe";
string arguments = "hellotext";
ProcessStartInfo info = new ProcessStartInfo(command, arguments);
// Redirect the standard output of the process.
info.RedirectStandardOutput = true;
info.RedirectStandardError = true;
// Set UseShellExecute to false for redirection
info.UseShellExecute = false;
Process proc = new Process();
proc.StartInfo = info;
proc.EnableRaisingEvents = true;
// Set our event handler to asynchronously read the sort output.
proc.OutputDataReceived += new DataReceivedEventHandler(proc_OutputDataReceived);
proc.ErrorDataReceived += new DataReceivedEventHandler(proc_ErrorDataReceived);
proc.Exited += new EventHandler(proc_Exited);
proc.Start();
// Start the asynchronous read of the sort output stream. Note this line!
proc.BeginOutputReadLine();
proc.BeginErrorReadLine();
proc.WaitForExit();
Console.WriteLine("Exited (Main)");
}
static void proc_Exited(object sender, EventArgs e)
{
Console.WriteLine("Exited (Event)");
}
static void proc_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
Console.WriteLine("Error: {0}", e.Data);
}
static void proc_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
Console.WriteLine("Output data: {0}", e.Data);
}
小心張貼您的C#代碼的相關位? – 2010-09-09 19:41:31
你有'C'和C#應用程序的源代碼嗎?如果你展示了相關的部分,它可能會有所幫助。 – pmg 2010-09-09 19:41:42
當你說你將緩衝區設置爲null時,你使用的是setvbuf函數嗎? – 2010-09-09 19:45:41