如何复制进程的标准输出(复制,而不是重定向)?
有很多示例展示了如何重定向另一个应用程序的标准输出。但是,我想让应用程序保留其标准输出,并且仅在父进程中检索标准输出的副本。这可能吗?
我的场景:我有一些测试(使用 Visual Studio Test Runner)启动外部进程(服务器)来进行测试。服务器在其标准输出中输出许多有用的调试信息,我希望将其包含在测试结果中。
我可以捕获进程输出并通过 Trace.WriteLine 输出它,以便稍后在测试详细信息中显示它。但是,如果在测试运行时看到服务器窗口及其输出以查看当前进度(测试可能运行很长时间),那就太好了。
所以我正在寻找复制这些信息而不是简单地重定向它的方法。
有什么想法吗?
there are a lot of examples that show how to redirect the stdout of another application. However I would like to let the application keep its stdout and only retrieve a copy of the stdout in my parent process. Is this possible?
My scenario: I have some tests (using Visual Studio Test Runner) which start an external process (server) to do their testing. The server outputs a lot of useful debug information in its stdout which I would like to include in my test results.
I can capture the process output and output it via Trace.WriteLine to let it show up in the test details later. However it would be nice to see the server window with its output while the test is running to see the current progress (test can be running a long time).
So I'm looking for ways to copy this information instead of simply redirecting it.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编写一个将 STDIN 转发到 STDOUT 的小程序,同时用它做其他事情怎么样?
然后,您可以将启动服务器进程的命令替换为启动服务器进程并将其输出传送到上述实用程序的命令。这样您就可以通过编程方式访问输出并在输出窗口中实时查看它。
What about writing a small program that forwards STDIN to STDOUT, while at the same time doing something else with it as well?
You could then replace the command that starts the server process with one that starts it and pipes its output to the above utility. That way you 'll have both programmatic access to the output and see it in real time in the output window.
这对你有用吗?
Would this work for you?