Pass data captured from a Python code to Shell Script

2

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

if umid is not None and temp is not None:
     print("Temperatura = {0:0.1f}Umidade{1:0.1f}\n").format(temp,umid);
    
asked by anonymous 20.10.2016 / 04:20

1 answer

2

Do this:

from subprocess import call

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

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

In the example above, it's as if I have been calling directly 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, such as 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 response from Stackoverflow English

    
20.10.2016 / 13:06