0

I have a build system that runs a build script then executes the program. The problem is that any output the program does is not printed until the application ends.

I tried running the program from the batch script and with the following :

{
    "cmd": "build.bat Release & cd bin & .\\editor.exe & cd ..",
    "working_dir": "${project_path:${folder}}",
    "shell": true,
}

Is there anything to do to avoid this behaviour ?

Here is some simple c++ code that reproduces the problem :

#include <stdio.h>
#include <thread>

int main(int argc, char** argv)
{    
    using namespace std::chrono_literals;

    fprintf(stderr, "Hello, World\n");
    std::this_thread::sleep_for(2s);

    return 0;
}

EDIT: As OdatNurd pointed it out, calling fflush in the c++ code does the job. But I would prefer not having to modify my source code to have it work properly with sublime. For me, the tool should adapt to the code, not the other way around.

EDIT2: It appears that this is not happening on Linux, so I guess this is some Windows specific stuff. I updated the title in consequence.

cmourglia
  • 2,423
  • 1
  • 17
  • 33
  • 1
    Try flushing stderr with `fflush` before the sleep. – OdatNurd Oct 22 '16 at 12:15
  • Well, that does the job but I would prefer a solution dependant only on sublime, and not impacting my code – cmourglia Oct 22 '16 at 12:36
  • True that; the underlying issue is that the OS gets to decide if the output handles are buffered or not. I think in order to fix it in Sublime you would need to modify `exec.py` in the `Default` package to re-open the output handles as unbuffered. I'm not 100% sure that's possible however. – OdatNurd Oct 22 '16 at 15:48
  • @OdatNurd yes, unbuffered file handles are possible. See the arguments to [`open()`](https://docs.python.org/3/library/functions.html#open). Something similar should be possible with `sys.stdout` and relatives as well. – MattDMo Oct 22 '16 at 19:46

0 Answers0