gpt4 book ai didi

c# - 如何将所有文本从控制台获取到字符串?

转载 作者:太空宇宙 更新时间:2023-11-03 10:41:22 25 4
gpt4 key购买 nike

我是这样测试的:

NUnit.ConsoleRunner.Runner.Main(new string[]
{
System.Reflection.Assembly.GetExecutingAssembly().Location,"OpenShop_Firefox.dll",
});

我想将所有文本从控制台获取到一个字符串。什么是最好的方法?

最佳答案

您需要将 Console.Out 设置为您选择的流:

using (StringWriter stringWriter = new StringWriter())
{
Console.SetOut(stringWriter);

NUnit.ConsoleRunner.Runner.Main(new string[]
{
System.Reflection.Assembly.GetExecutingAssembly().Location,
"OpenShop_Firefox.dll"
});

string allConsoleOutput = stringWriter.ToString();
}

关于c# - 如何将所有文本从控制台获取到字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25241323/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com