简体   繁体   中英

Capturing stdout from a subprocess run during a test in mstest

I'm using MSTest to run some tests (in C#). One of the routines I'm testing creates a new process and that process often dumps some output stdout. I'd like to capture that output in the test. While it isn't important to see if the test failed, it is very helpful in figuring out why the test failed. How can I do this?

Some details. Unfortunately, I can't touch the code that is creating the process. Worse, it is C++, and it is being called via a C++/CLI wrapper. If I create a .NET console app (in C#) then the stdout of the subprocess I want to capture does appear in the window of the console app when it makes the call. When I run the same code in the MSTest context the sub-process creation pops up a new window, and the subprocess dumps its output in that window. It is that output I'd like to capture if at all possible.

Many thanks!

如果在测试结果完成后双击测试结果,您还将看到一个包含stdout的报告页面。然后您可以在此处看到将一个流程对象的stdout重定向到另一个流程对象的stdin,如何将子流程stdout重定向并仅对此进行镜像在测试的标准输出中(即调用Console.Write())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM