AttachConsole() shows data on pipe but the > operator doesn't correctly redirect to file

Viewed 2610

I made a WinForms application running on the .NET Framework 4.0. It writes on the parent console using the Console.WriteLine() method, after calling (once, at startup) the Win32 API function AttachConsole(-1).

It works flawlessly as long as I just need to show the output on screen. Unfortunately when I use a batch with a pipe redirection operator like this:

application.exe > output.txt

it just creates an empty file. Maybe there's some problem related to the actual pipe being addressed when I use AttachConsole? Why the command prompt can't catch the data and put it on the file? Does anyone know about any problems related to such a scenario?

1 Answers
Related