Sublime Forum

Build system results stop receiving messages during run

#1

I’m making a C++ windows app (using GLFW). I have setup a Sublime project with a build system that runs a bash script to make then run the app.
Sublime receives gcc messages in the build results view as they happen, but as soon as the app starts I don’t received anything anymore, until I close the app, then all the app messages are dumped at once.
If I run the same app in the terminal, messages are printed live.

Am I doing something wrong? Is that a known behavior of Sublime? any workarounds to get the prints live?

0 Likes

How to get build output in real-time?
#2

The output is being buffered. Either turn off stdout buffering or flush the buffer after each output.

0 Likes

#3

How do I turn it off? Who’s even doing the buffering, Sublime? Python? my C++ app?
Why is it not buffered in the terminal?

0 Likes

#4

Your app is the culprit here, or more technically the underlying output libraries. Roughly speaking, an output handle can be:

  • Completely unbuffered, so any and all writes to the file immediately go to the destination

  • Buffered, wherein there is a buffer of some size and writes to the file go to the buffer, which isn’t sent to the destination until the buffer is filled up

  • “Line” buffered, in which the buffer holds only a single line and so all output gets buffered until a newline is seen, and then the buffered data gets sent to the destination.

It’s not uncommon for the scheme that the library uses to change based on the situation it finds itself in. For example, the buffer for stdout might be completely unbuffered when the library knows that the output handle is connected to a terminal, but line or fully buffered when it is not.

That helps your program more efficiently cooperate in shell pipes and re-directions between commands while being more “interactive” while you’re running it directly.

Sublime is just capturing the output as it’s being sent, so in order to have your program generate output to the build system while it’s running you need to do something like flush the handle at knows points or change the buffer size/scheme that the library is using to tell it how you want it to act.

1 Like

#5

There are several ways to stop stdout/stderr being buffered, personally I call setbuf and set the buffer to nil:

http://man7.org/linux/man-pages/man3/setbuf.3.html

0 Likes