Python Forum

Full Version: Help with run commands from a python script
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I'm a noob in python and I'm trying hard to get it to work.

I want to run a command line from a python script that will launch a blender render like so :
import os
command = "C:\Program Files\Blender Foundation\Blender\blender untitled 02.blend -b -a"
os.system(command)
or
import subprocess
subprocess.Popen("C:\Program Files\Blender Foundation\Blender\blender.exe untitled 02.blend -b -a")
But it doesn't work. Help will be appreciated..
If pass in a string command need shell=True.
Better and safer to pass in a list.
Can try:
import subprocess

subprocess.Popen([r'C:\Program Files\Blender Foundation\Blender\blender.exe', 'untitled', '02.blend', '-b', '-a'])
If you use blender some should also add it to Windows Path.
Then can call just blender.
import subprocess

subprocess.Popen(['blender', 'untitled', '02.blend', '-b', '-a'])
Thank you for your answer, but how can I pass a variable with this?

I tried that and didn't work :
newCol = [0.22447,1, 0.22447,1]
subprocess.Popen([r'C:\Program Files\Blender Foundation\Blender\blender.exe', 'untitled02.blend', '-b', '-a', '--', newCol])
I guess --newCol is one command?
All command should be one(string) element in the list.
[r'C:\Program Files\Blender Foundation\Blender\blender.exe', 'untitled02.blend', '-b', '-a', '--newCol']
i'd use subprocess.call ... but i do things in weird ways.
Here it is what I was working on.

https://www.facebook.com/shibigraphicspo...6461081783

Automation Project - Python & Blender
This can be very useful while making video mock-ups for presenting a product to a client.

And again, thank you snippsat for your answers :)
facebook does not let me see things. it wants me to sign in to see stuff. to be able to sign in i would have to sign up. but i choose not to do that.

can you post it somewhere else?