当PHP中的shell_exec()执行脚本时,Python open()函数不起作用 [英] Python open() function not working when script executed by shell_exec() in PHP

查看:291
本文介绍了当PHP中的shell_exec()执行脚本时,Python open()函数不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Python脚本中有一个open()命令,该命令在以w模式运行在Raspberry Pi上的Apache服务中打开文件data.json.该脚本又由PHP使用shell_exec命令运行.当脚本单独运行时,Python代码起作用. 但是,在由PHP运行时不起作用.有谁知道为什么会这样,还是需要更多信息?预先感谢您的帮助!

I have a open() command in my Python script which opens the file data.json in my Apache serve running on Raspberry Pi in w mode. This script in turn is run by PHP using the shell_exec command. When the script is run alone, the Python code works. However, it does not function when run by PHP. Does anyone have any idea why this is happening, or is more information needed? Thank you in advance for your help!

推荐答案

感谢user2693053解决此问题:

Thank you to user2693053 for solving this problem:

听起来像是特权问题,尽管我经验不足 从php调用Python以了解是否可能是一个问题 在这里.

Sounds like a privilege issue, although I am not experienced enough with calling Python from php to know whether that could be an issue here.

是的,这是一个特权问题!我通过在/var/www/html目录中执行sudo chmod 777 *命令来解决此问题.

and yes, it is a privilege issue! I fixed the problem by doing the sudo chmod 777 * command in the /var/www/html directory.

这篇关于当PHP中的shell_exec()执行脚本时,Python open()函数不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆