Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute terminal commands in python3 [duplicate]

I am on a Raspberry Pi, and I am using a program called fswebcam, which allows you to take pictures with a webcam.

~$ fswebcam image.jpg 

That command if entered in terminal takes a picture and saves it to your computer, however I want to build a simple python program that can access the terminal and execute that same command as I have listed above.

I have tried to import os and use os.system('fswebcam image.jpg') But it isn't working for me.

How can I have python execute terminal commands?

like image 477
BrandonMayU Avatar asked Jan 01 '16 00:01

BrandonMayU


1 Answers

Use the subprocess module:

import subprocess subprocess.Popen(["fswebcam", "image.jpg"]) 
like image 58
vesche Avatar answered Sep 29 '22 16:09

vesche