如何复制进程的标准输出(复制而不是重定向)? [英] How can I copy the stdout of a process (copy, not redirect)?

查看:61
本文介绍了如何复制进程的标准输出(复制而不是重定向)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有很多示例说明了如何重定向另一个应用程序的标准输出.但是,我想让应用程序保留其stdout并仅在我的父进程中检索stdout的副本.这可能吗?

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?

我的场景:我有一些测试(使用Visual Studio Test Runner),这些测试启动外部进程(服务器)来进行测试.服务器会在其stdout中输出很多有用的调试信息,我想在测试结果中包含这些信息.

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.

我可以捕获过程输出,并通过Trace.WriteLine将其输出,以使其稍后显示在测试详细信息中.但是,最好在测试运行时看到服务器窗口及其输出以查看当前进度(测试可以运行很长时间).

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.

有什么想法吗?

推荐答案

编写一个将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.

这篇关于如何复制进程的标准输出(复制而不是重定向)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆