简体   繁体   English

exec()php函数返回不需要的空文件

[英]exec() php function returns an unwanted empty file

I am running a simple PHP script which calls a Python script using exec() in PHP to activate GPIO pins on a Raspberry Pi to turn (or keep) a light on or off. 我正在运行一个简单的PHP脚本,该脚本使用PHP中的exec()调用Python脚本来激活Raspberry Pi上的GPIO引脚以打开(或保持)开灯或关灯。 The script is called by cron every 5 minutes. cron每5分钟调用一次脚本。 It works fine, but writes an empty file with the same name as the script each time the script is run. 它可以正常工作,但是每次运行脚本时都会写入一个与脚本名称相同的空文件。 The key part of the script is: 该脚本的关键部分是:

$command = "sudo python lights.py 0"; $result = shell_exec($command);

I have tried it like this: 我已经这样尝试过了:

$command = "sudo python lights.py 1"; $result = exec($command); 

And I have tried it with or without echo $result . 而且我已经尝试过有或没有echo $result In all cases I get the empty file written to the /home/pi directory. 在所有情况下,我都会将空文件写入/home/pi目录。 The script is run in /var/www/working directory . 该脚本在/var/www/working directory
The cron script is cron脚本是

*/5 * * * * /usr/bin/wget [lan_address]/working/lampRoutine.php >> dev/null 2>&1

Can anyone help? 有人可以帮忙吗?

I have found a solution. 我找到了解决方案。 The problem was with the cron script. 问题出在cron脚本上。 If I add the argument '-O' to the wget command I get no empty file. 如果我在wget命令中添加参数“ -O”,则不会得到空文件。

wget -O - https://[lanAddress]/path/To/Script >> /dev/null 2>&1 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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