2
$\begingroup$

I'm trying to capture blender's console output to a file (as a result of a great suggestions from @Rich Sedman in another post) with something like

$ blender > /tmp/output.txt

The problem is that I need output.txt have always the content of the console but blender is buffering this output and not always I can access the text. I tried all kinds of flushing (line sys.stdout.flush(), or sys.stdout = fopen(sys.stdout.fileno(), 'w', 0), etc) and nothing seems to force an unbuffered output.

Is there a way to really force blender to use an unbuffered console?

Thanks!

$\endgroup$

1 Answer 1

2
$\begingroup$

Figure out the problem. The python interpreter can be forced to use unbuffered prints if we set the PYTHONUNBUFFERED environment variable. Just use

export PYTHONUNBUFFERED=on

Nevertheless that still did not solved completely my problem because I had a piped grep together with blender. Hence, although blender was running unbuffered outputs to console, grep was... Just used grep --line-buffered (saw that in s very good post about stdout here https://eklitzke.org/stdout-buffering)

Hope that helps somebody! Thanks for everyone that tried to help!

/edit: Since 16.01.2020, to make this work you have to launch blender with --python-use-system-env to make it work. Source: https://developer.blender.org/rBS7c2f0074f3fe2411daa7a6e351d7cbc535246871

$\endgroup$
3
  • $\begingroup$ Does it work on Windows though? I've tried with SET PYTHONUNBUFFERED=on and powershell $Env:PYTHONUNBUFFERED="on" but still can't get it to print content on live mode, rather than waiting for process end. $\endgroup$ Commented Jan 27, 2021 at 18:46
  • $\begingroup$ I'm afraid I don't know wether it works or not on windows. Probably all the "flush" policies might be quite different from Linux/Mac. Even the grep might flush the output differently, check it out. $\endgroup$ Commented Jan 29, 2021 at 0:43
  • 1
    $\begingroup$ developer.blender.org/… TL;DR: it works, but since 16.01.2020 you have to launch blender with --python-use-system-env to make it work. $\endgroup$ Commented Jan 30, 2021 at 1:04

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.