Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress 3rd party library console output?

I need to call a 3rd party library that happens to spew a bunch of stuff to the console. The code simply like this...

int MyMethod(int a)
{
   int b = ThirdPartyLibrary.Transform(a);  // spews unwanted console output
   return b;
}

Is there an easy way to suppress the unwanted console output from ThirdPartyLibrary? For performance reasons, new processes or threads cannot be used in the solution.

like image 715
noctonura Avatar asked Sep 11 '09 17:09

noctonura


1 Answers

Well you can use Console.SetOut to an implementation of TextWriter which doesn't write anywhere:

Console.SetOut(TextWriter.Null);

That will suppress all console output though. You could always maintain a reference to the original Console.Out writer and use that for your own output.

like image 196
Jon Skeet Avatar answered Oct 11 '22 05:10

Jon Skeet