How to capture stdout in Visual Studio 2019?

How can I get Output window to show stdout in VS19? I’ve tried the different choices in the dropdown list, and tried the different tabs, but I don’t get any messages that seems to come from std::cout or similar methods.


I’m building Eeschema as x64-Debug and I’ve tried both Debug -> Start Debugging and Debug -> Start Without Debugging

I’m not an expert on this but I’m pretty sure a windows app has to be specifically created as console program to have stdout/stderr mapped. I.e. gui apps don’t normally have those streams mapped.

If you are trying to debug something using those streams try using wxMesageBox or wxLog* methods.

Windows null routes stdout by default in gui type applications. It only works in console applications.

wxLog however will get captured by the MSVC window. Additionally I believe it’s because wxWidgets is using the Windows OutputDebugString function which you can call yourself

1 Like

Thank you both! I had no idea it was this hard to get the stdout prints in VS19. I’m used to Qt where it’s a breeze.

OutputDebugStringW did the trick!

This code gives me readable output when building using Debug -> Start Debugging:

wstring my_str = L"Hello World";
LPCWSTR wide_string;
wide_string = my_str.c_str();
OutputDebugStringW( wide_string );

Now I can simply wrap this in a function. :slight_smile:

1 Like

The alternative is to learn how wxLogTrace works, it also calls OutputDebugString but it has a enable/disable system that’s slightly a PITA and I always forget how to do it because the documentation is sparse.

If you plan on submitting anything as a merge request, we will not accept anything that bypasses wxLogXXXX functions if you want to leave debug messages. Otherwise knock yourself out for your own purposes.

Thanks for the clarification. If I ever manage to solve a bug in Kicad it will most definitely be something very small so no need to leave debug prints in the code by the time I do a merge request.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.