使用特定库时,Python 脚本不会从 php 执行 [英] Python script won't exec from php when specific library is used
问题描述
我正在尝试执行 Python 脚本以获取和设置 ROS 中的参数服务器.当我运行任何其他简单的 Python 脚本(例如打印Hello")时,我会返回 PHP 中的值.但是当我运行这段代码时:
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!
我在 PHP 中所做的就是:
All I'm doing in PHP is:
$output = exec("python path/script.py")
echo $output;
我试过shell_exec,我试过在命令中使用python,但没有试过.我也试过/usr/bin/python 仍然不适用于这个特定的代码,但一切都适用于简单的打印!
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!
推荐答案
事实证明 Apache 的用户没有所需的环境变量.因此,您必须在 Apache 中添加您需要的环境变量路径.您可以在 此处设置它们
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
这篇关于使用特定库时,Python 脚本不会从 php 执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!