1

I have a C# application in which I'm trying to redirect some text written on to stderror. The text which is written to stderror is actually written by calling a function that is present in some other dll. I have used CreatePipe, SetStdHandle and ReadFile (in that order) to achieve the mentioned functionality. While I am able to redirect any text that is written in the same C# file using Console.SetError, the text that is written to stderr by the other dll still gets written on the native stderr and is not redirected.

Is there any way to catch/redirect this text? Thanks.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
AarCee
  • 833
  • 2
  • 11
  • 24
  • I'd like to add that I'm not executing a new process and hence will not be able to change its start info, as has been explained in some other answers here on SO. – AarCee Apr 06 '12 at 12:01
  • So you perform p/invoke to a dll writing to stderr. And even you redirected Console.ErrorStream, dll output is not redirected? – abatishchev Apr 06 '12 at 12:38
  • I don't use p/invoke, I just call a function that is implemented in another dll.And I am ignorant about Console.ErrorStream, please elucidate, I just know about SetIn, SetOut and SetError for Console class that could be relevant here. – AarCee Apr 06 '12 at 12:48
  • Also, I have read on the net some people mentioning about consoles being different for managed (in this case, my C# application) and unmanaged (in this case, where the dll might be using win32 functions to write to stderror) codes. If this is indeed the issue here, can it be overcome? – AarCee Apr 06 '12 at 12:53
  • Actually you can redirect output/input/error stream (SetX method), and in the same time access them (X property). – abatishchev Apr 06 '12 at 13:43
  • Do you mean the setx method for setting environment variables? I don't think that would be the best way to go about this. If you still think so, could you please provide an example of using it? Thanks. – AarCee Apr 09 '12 at 03:47
  • That was just a remark, actually, you said you know about Console.SetX methods to set, and I mentioned in addition about Console.X properties to access accordingly. – abatishchev Apr 09 '12 at 06:24
  • I'll think about the question itself more – abatishchev Apr 09 '12 at 06:24
  • Can anybody please provide some pointers? – AarCee Apr 18 '12 at 04:26

0 Answers0