16

If I remember correctly, Windows applications can be compiled as console or GUI applications. One of the main differences is that console applications get a console automatically, while GUI applications do not (although they could get one if they wanted by calling AllocConsole).

Common wisdom says if you use printf or std::cout from a GUI application, that output simply goes nowhere, because there's no console to print it to. But I know it's possible to read it, because when I run some applications from a terminal on Linux using Wine, I can read the output of printf and similar functions. (Yes, I'm sure it's the application printing that, not Wine.)

How could I do that on Windows? I've tried DebugView and even though it shows a bit of debug text coming from the application, it doesn't show as much as Wine does, probably because DebugView is restricted to calls to OutputDebugString.

5
  • No; What you describe must be programmed by the author of the application.
    – Ramhound
    Apr 12, 2017 at 0:21
  • 2
    To my instinct I think you can try to run the program from command prompt and redirect the output to a file, like gui_application.exe > output.txt. Not sure if it works, and I am curious whether it works.
    – Kenneth L
    Apr 12, 2017 at 3:26
  • @KennethL yes, it works. Interesting. Thanks for the tip.
    – dzz
    Apr 14, 2017 at 19:24
  • You write "If I remember correctly, Windows applications can be compiled as console or GUI applications" <-- Do you have a source for this claim? Certainly visual studio offers different templates.. But that doesn't mean different compilers!!
    – barlop
    Oct 20, 2020 at 20:28
  • 3
    I did not mean to say different compilers were used. Whether an application is a CLI or GUI application is marked, as far as I know, as a flag in the executable header.
    – dzz
    Mar 8, 2021 at 13:31

1 Answer 1

11

Invoke it as gui_application.exe > output.txt to have stdout go into the file

Invoke it as gui_application.exe > output.txt 2>&1 to have stdout and stderr go into the file

If you are using the windows start command, you need to remember that start is an application itself, therefore start /wait gui_application.exe > output.txt will not do what you want because it is redirecting the stdout for start.

However you can escape the pertinent values:

Invoke it as start /wait gui_application.exe ^> output.txt to have stdout go into the file

Invoke it as start /wait gui_application.exe ^> output.txt 2^>^&1 to have stdout and stderr go into the file

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .