我的Python脚本返回:
python /home/pi/sht/sht31.py
False
True
False
Temperature: 8.10668945312
Humidity: 83.49609375
我需要将湿度和温度打印到index.php中
我尝试过:
exec('sudo python /home/pi/sht/sht31.py' , $output);
var_dump($output);
但输出是:
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" }
可以仅提取温度和湿度吗?
您可以将其添加到代码中,然后在运行时添加两个文件,例如:python ex0.py ex0.txt ex1.txt我希望如果对不起,祝您度过愉快的一天,对您有所帮助
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()
这样就可以了:
print "$output[1] <br />";
echo $output[0];