I'm starting Blender 2.79 with a --python
flag to run a python script.
On a Mac, print()
statements show up in the terminal window as expected. On Windows, when executing the same command in git bash, print()
statements appear until the main Blender window opens and then output stops.
Where does console output go says on Windows output should go to the "Console Window," but when I select this menu option, the main Blender window loses focus and nothing else happens. (If I start Blender normally the Console Window appears as expected.)
Things that didn't work for me:
- Writing to the console: How can I display what happens in the system console inside blender's console?
- Starting blender.exe with the
-con
flag
Things that kind of worked:
- Overriding
print()
as in Blender script run print to console works but only after I quit Blender. -_- - The
redirect_stdout
trick from How to redirect output from 'bpy.ops.*'? prints output if I capture it withstdout.seek(0); print(stdout.read())
, but only after I quit Blender. -_- os.system('echo test')
works, but if it's possible to get regular python print statements working I'd like to know how.
print()
, but it's not comprehensive: def print(*args): strings = [] for arg in args: strings.append(str(arg)) output = ' '.join(strings) os.system('echo '+output) This works as expected for everything I've tried except objects, eg:print(datetime)
should return<module 'datetime' (built-in)>
as it does in a standard python console, but in the context of my script it returns: >The syntax of the command is incorrect. Can anyone improve this? $\endgroup$os.system('echo "%s"' % output)
will need to make sure any quotes in output are escaped. Suggest never usingprint(str + str)
can use formatting orprint(str, str)
often suffices. $\endgroup$os.system()
should be treated very, very carefully in order not to shoot yourself in the foot. Think of this command as "this potentially formats my harddisk/SSD". $\endgroup$