C
C#Tacti Tacoz

Redirecting the native standard output stream

I need to call into native code the problem is that it writes some of it's output using stdout. Is it possible to redirect stdout to a file (or one of the virtual file streams types) and then direct it back to the default console output afterwards? System.Console.SetOut doesn't effect native code at all and only changes logging done via System.Console.WriteLine (and co) I can find C++ examples to do so, but they do not seem to use any easily pinvokeable library like the method I tried below. Creating my own native dll for this seems a bit overkill. https://learn.microsoft.com/en-us/windows/console/setstdhandle Seems to be related but has no effect, even though it's returning non zero like the documentation says. I would like to clarify this is native code called within the same process not managed code starting a native process. Ways to do that is well documented.
SetStdHandle function - Windows Console
Sets the handle for the specified standard device (standard input, standard output, or standard error).