问题
I do test in that way:
NUnit.ConsoleRunner.Runner.Main(new string[]
{
System.Reflection.Assembly.GetExecutingAssembly().Location,"OpenShop_Firefox.dll",
});
And i want to get all text from console to one string. What is the best way?
回答1:
You need to set Console.Out
to a stream of your choosing:
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();
}
来源:https://stackoverflow.com/questions/25241323/how-to-get-all-text-from-console-to-string