Python script won't exec from php when specific library is used

*爱你&永不变心* 提交于 2019-12-08 13:18:34

问题


Im trying to execute a Python script to get and set the parameter server in ROS. When I run any other simple python script that for example prints "Hello", I get back the value in PHP. But when I run this code:

 #!/usr/bin/env python
 import roslib
 import rospy
 import sys
 import re
 import string

 get = rospy.get_param("param")
 print get

I get an empty echo. However this code works fine in the terminal!

All I'm doing in PHP is:

 $output = exec("python path/script.py")
 echo $output;

I tried shell_exec, I tried with python in the command, and without. I also tried /usr/bin/python still it won't work for this specific code, but everything works for a simple print!


回答1:


It turns out that Apache's user doesnt have the required environment variables. So you have to add the environment variables paths you need in Apache's.. You can set them out here



来源:https://stackoverflow.com/questions/34918981/python-script-wont-exec-from-php-when-specific-library-is-used

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!