2

Given an existing Win32 GUI application, how can I see the messages it sends to stdout and stderr (file descriptors 1 and 2, cout and cerr, etc.)?

I cannot modify the application itself, and I know it simply calls C's printf internally.


There are a few similar questions already (e.g. here or here), but the solutions suggest modifying the executable. One answer from 2009 to a similar question recommends using DebugView, but I couldn't get it to display the actual stdout of the process, only kernel and system messages.

For background, I have a GUI application that was compiled a few years ago. The author didn't really know how Windows apps work, and so he just compiled his Linux code into an EXE. His code follows the Unix convention of sending debug messages to stdout while displaying graphics at the same time. Now the app broke, and it seems the relevant into should be in stdout, but I can't view it. I don't have the sources so I can't recompile it.


A minimal example

// main.c
#include <stdio.h>
int main() // sic, not WinMain()
{
    printf("%s\n", "Hello World!");
    return 0;
}

compiled as

mingw main.c -mwindows

produces a.exe. How can I launch a.exe, without modifying its source code, to be able to see the message?

OLEGSHA
  • 388
  • 3
  • 13
  • Have you tried launching it from a console window? – Ken White Oct 19 '22 at 16:48
  • 1
    Yes, I have. Application launches in background and no output is visible. Redirecting output (with `>log.log` or `1>log.log`) generates empty files. – OLEGSHA Oct 19 '22 at 16:58
  • You might be able to get what you want by modifying the PE header to change the [subsystem](https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#windows-subsystem) from Windows to Console. – Luke Oct 21 '22 at 11:10

0 Answers0