简体   繁体   中英

get variable from python script into php page

my Python script returns:

python /home/pi/sht/sht31.py
False
True
False
Temperature: 8.10668945312
Humidity: 83.49609375

I need to print humidity and Temperature into an index.php

I tried:

exec('sudo python /home/pi/sht/sht31.py' , $output);
var_dump($output);

but output is:

array(5) { [0]=> string(5) "False" [1]=> string(4) "True" [2]=> string(5) "False" [3]=>       string(26) "Temperature: 8.07464599609" [4]=> string(23) "Humidity: 83.5327148438" }

it is possible to extract only temperature and humidity ?

You can add this into your code and when you run it add the two files for example: python ex0.py ex0.txt ex1.txt I hope this helps if it doesn't sorry have a great day

from sys import argv
from os.path import exists

script, from_file, to_file = argv 
print ("Copying from %s to %s.") % (from_file, to_file)

in_file=open(from_file)
indata= in_file.read()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM