douhua1890 2016-01-12 20:42
浏览 428
已采纳

从php调用python,返回值为2

I have a python script who is returning 2 values, humidity and temperature:

Temperature: 1.58050537109
Humidity: 89.2761230469

I call this srcipt from a PHP page but only one value is printed

<?php
echo exec("sudo python /home/pi/sht/sht31.py 2>&1");
?>

and only one humidity is printed. Could you please help me to print both value ? Thank you

  • 写回答

2条回答 默认 最新

  • duangu1645 2016-01-12 20:45
    关注

    If you call exec() with only command string, then it will return only the last line of output. To capture everything call it with second parameter to get all output:

    exec('command', $output);
    var_dump($output);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?