0
$\begingroup$

I'm trying to use blender as a part of a larger script, as such I wanted to run Blender a couple of times to figure out some important environment settings, something along the lines:

blender=${1:-blender}

python=$(${blender} --background --python-expr "import sys; print(sys.executable)")
addons=$(${blender} --background --python-expr "import bpy; print(bpy.utils.user_resource('SCRIPTS', path='addons'))")

echo ${python}
echo ${addons}

While this works, Blender outputs a lot of extra junk after the print, e.g.:

/Applications/Blender.app/Contents/Resources/3.4/python/bin/python3.10 Blender 3.4.1 (hash 55485cb379f7 built 2022-12-20 00:48:52) Read prefs: /Users/gustaf/Library/Application Support/Blender/3.4/config/userpref.blend Blender quit
/Users/gustaf/Library/Application Support/Blender/3.4/scripts/addons Blender 3.4.1 (hash 55485cb379f7 built 2022-12-20 00:48:52) Read prefs: /Users/gustaf/Library/Application Support/Blender/3.4/config/userpref.blend Blender quit

Is it possible to tell Blender to suppress the remaining (uninteresting) output? I.e., avoid printing this:

Blender 3.4.1 (hash 55485cb379f7 built 2022-12-20 00:48:52) Read prefs: /Users/gustaf/Library/Application Support/Blender/3.4/config/userpref.blend Blender quit
$\endgroup$

1 Answer 1

0
$\begingroup$

Arguably not a solution, but a workaround is to simply remove the extra output after the fact:

#!/usr/bin/env bash

script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
blender=${1:-blender}

# Find the Blender python binary and addons directory paths.
empty=$(${blender} --background --python-expr "print()")
python=$(${blender} --background --python-expr "import sys; print(sys.executable)")
addons=$(${blender} --background --python-expr "import bpy; print(bpy.utils.user_resource('SCRIPTS', path='addons'))")

# Strip additional junk from the Blender output.
python="${python::-${#empty}}"
addons="${addons::-${#empty}}"
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .