Python Forum
Help with run commands from a python script
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with run commands from a python script
#1
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..
Reply
#2
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'])
Reply
#3
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])
Reply
#4
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']
Reply
#5
i'd use subprocess.call ... but i do things in weird ways.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#6
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 :)
Reply
#7
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?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 3,290 Jun-29-2023, 11:57 AM
Last Post: gologica
  Sending string commands from Python to a bluetooth device Rovelin 13 9,531 Aug-31-2021, 06:40 PM
Last Post: deanhystad
  Python library for win32 console commands eldiener 3 3,488 Aug-24-2021, 10:28 PM
Last Post: bowlofred
  Possible to execute a python script before log off/shutdown with input commands? Kaltex 1 2,282 May-18-2021, 06:31 AM
Last Post: Skaperen
  cant use ping, sudo or other commands in remote shell script. throwaway34 7 3,619 May-17-2021, 11:29 AM
Last Post: throwaway34
  Raspi Commands via Python (VS Code) Script AS4188 5 2,830 Oct-21-2020, 03:49 PM
Last Post: AS4188
  How to kill a bash script running as root from a python script? jc_lafleur 4 5,941 Jun-26-2020, 10:50 PM
Last Post: jc_lafleur
  crontab on RHEL7 not calling python script wrapped in shell script benthomson 1 2,315 May-28-2020, 05:27 PM
Last Post: micseydel
  how to get PID's of linux commands executed through python modules? Manikandan_PS 4 3,063 Mar-12-2020, 07:16 AM
Last Post: Manikandan_PS
  Questions re: my first python app (GUI, cross-platform, admin/root-level commands)? DonnyBahama 0 1,739 Feb-27-2020, 08:14 PM
Last Post: DonnyBahama

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020