Python script has no effect when running as background I'm trying to render some still images of a scene but switch the image texture using a script with the Blender command line. I made a script to set the image of an image texture node in the scene. When I run it within Blender with Run Script or run it with --python-text when launching Blender from the terminal the image is set correctly, but it has no effect when I run it along as GUI-less background with -b. 

I'm still finding my way around the API so this is the extent of the script:

import bpy
import os

def set_texture_image(img):
    bpy.data.objects["Cube"].select = true
    mat_tree = bpy.data.objects["Cube"].material_slots[0].material.node_tree
    mat_tree.nodes["Image Texture.001"].image = img


new_image = bpy.data.images.load('//../../Pictures/cubes.png')
set_texture_image(new_image)
I was missing something obvious: I need to render from within the script after I make the changes I need. This exchange helped. Otherwise it renders the image with the command line arguments before the script is run. If I launched Blender with the script or ran the script normally I could run a render later and it worked. 

Adding bpy.ops.render.render(write_still=True) worked. All the render settings are set within the scene with the UI.