Passing data captured from Python code to Shell Script


I would like to know what to do to take this data captured from a DHT11 sensor (Python Code [Temperature and Humidity]) and pass it to a Shell script

if umid is not None and temp is not None:
     print("Temperatura = {0:0.1f}Umidade{1:0.1f}\n").format(temp,umid);


Do like this:

from subprocess import call

call(["sh", "",  temp, umid])

You will need to use a list . The first item in this list is the command and the rest are the arguments.

In the example above, it's like I was calling straight from Bash (assuming the temp and umid values):

sh 30.6 10.2

There are several ways to do this in Python, for example using os.system :

import os
os.system("sh {0:0.1f} {1:0.1f}".format(temp,umid))

If you want more options, you can check out this Stackoverflow answer.

Scroll to Top