php exec没有得到完整的输出
首先:我在这里读了很多关于类似问题的答案;但没有任何帮助 我的问题是:我有一个php exec没有得到完整的输出,php,python,Php,Python,首先:我在这里读了很多关于类似问题的答案;但没有任何帮助 我的问题是:我有一个php文件,在那里我执行一个python文件。python文件读取传感器值(需要一些时间)并打印这些值。然后,我想在我的php文件中回显这些值 我的php文件: <?php $var1 = shell_exec('bash -c "> /var/www/html/log.txt"'); exec('bash -c "python /var/www/html/readTempAn
php
文件,在那里我执行一个python
文件。python文件读取传感器值(需要一些时间)并打印这些值。然后,我想在我的php文件中回显这些值
我的php文件:
<?php
$var1 = shell_exec('bash -c "> /var/www/html/log.txt"');
exec('bash -c "python /var/www/html/readTempAndHumSensor.py"',$output);
echo count($output);
?>
在
$output
中,存储test,但不存储其他值。注意:读取传感器数据大约需要2秒为什么计数()?为什么要使用bash
清空文件?只需使用文件内容(“,”/var/www/html/log.txt”)代码>@nogad count只是为了不知道数组的大小。很抱歉,我可以在这个最小的示例中省略它。为什么在exec()
调用中使用bash-c
?只需执行exec(“python/var/www/html/readTempAndHumSensor.py”)
@Barmar good idea为什么计数()?为什么要使用bash
清空文件?只需使用文件内容(“,”/var/www/html/log.txt”)代码>@nogad count只是为了不知道数组的大小。很抱歉,我可以在这个最小的示例中省略它。为什么在exec()
调用中使用bash-c
?只需执行exec(“python/var/www/html/readTempAndHumSensor.py”)
@Barmar好主意
#!/usr/bin/env python
import Adafruit_DHT
print "test"
sensor = Adafruit_DHT.DHT22
gpio = 10
# read sensor values (takes aprox. 2s)
humidity, temperature = Adafruit_DHT.read_retry(sensor, gpio)
# Output
print int(temperature*10)
print int(humidity*10)