Pass captured data from a Python code to Shell Script

Asked

Viewed 68 times

3

I would like to know what to do to take this data captured from a DHT11 sensor (Python Code [Temperature and Humidity]) and pass them 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);
  • You either pass them one at a time, or multiples at a time?

1 answer

2

Do so:

from subprocess import call

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

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

In the above example, it is as if I had called straight from Bash (assuming the values of temp and umid):

sh caminho_do_script.sh 30.6 10.2

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

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

If you want more options, you can take a look at this answer from Stackoverflow English

Browser other questions tagged

You are not signed in. Login or sign up in order to post.