Capture/Redirect printf in kernels

Hi, I’m trying to redirect all console output to a custom console made with imgui. I’ve had a bit of trouble doing so with output that originates from printf in CUDA kernels as it seems to work differently than output made with print or cout from host side, e.g., solutions using cout.rdbuf do not work for the CUDA printfs.

Eventually I ended up with a hack where I’m using freopen to redirect all stdout to a file, then monitor it and load new text when the file changes. This works, so now I wanted to prevent windows from spawning a console along with the main window with #pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup"), but doing so stops all printf originating from CUDA, while cout or print from std still work.

Is there perhaps a recommended way of capturing printf from CUDA kernels?