C++ 如何在标准输出来自流时重新定向它

C++ 如何在标准输出来自流时重新定向它,c++,c++-cli,C++,C++ Cli,我试图从一个流程中重新定向标准输出,但我希望将一行一行重新定向为其他流程输出,而不是一次全部重新定向。现在,我的代码如下所示: proc->StartInfo->FileName = "ping.exe"; proc->StartInfo->UseShellExecute = false; proc->StartInfo->RedirectStandardOutput = true; proc->StartInfo->Arguments = "-n

我试图从一个流程中重新定向标准输出,但我希望将一行一行重新定向为其他流程输出,而不是一次全部重新定向。现在,我的代码如下所示:

proc->StartInfo->FileName = "ping.exe";
proc->StartInfo->UseShellExecute = false;
proc->StartInfo->RedirectStandardOutput = true;
proc->StartInfo->Arguments = "-n 1 www.google.com";
proc->Start();

StreamReader^ stream = proc->StandardOutput;


if(stream){
    //String^ s = stream->ReadToEnd();
    //Console::WriteLine(s);
    proc->WaitForExit();
    while(stream->Peek() >= 0)
    {
        Console::WriteLine(stream->ReadLine());
    }

}
但它要做的是等待进程退出,然后再打印所有Ping输出。如果以本机方式运行ping,则可以看到输出会随着HTTP请求的发出而周期性地出现。我基本上希望输出以相同的方式排队并重新定向,一行一行。

明白了:

String^ s;
        //Console::WriteLine(s);
        //proc->WaitForExit();
        while(s=stream->ReadLine())
        {
            Console::WriteLine(s);
        }
这很有效