将控制台重定向到.NET程序中的字符串 [英] Redirecting console to a string in a .NET program

查看:192
本文介绍了将控制台重定向到.NET程序中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案

对于你自己的进程, Console.SetOut 并将其重定向到构建在字符串构建器或内存流顶部的TextWriter。对于已启动的子进程,请使用 ProcessStartInfo.RedirectStandardOutput


How can I redirect whatever is written to the console to be written into a string?

解决方案

For your own process, Console.SetOut and redirect it to a TextWriter built on top of a string builder or memory stream. For a launched child process, use ProcessStartInfo.RedirectStandardOutput when launching the process.

这篇关于将控制台重定向到.NET程序中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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