【发布时间】:2015-08-01 03:52:11
【问题描述】:
让我详细说明一下:我正在尝试使用 proc_open 从 PHP 生成 catkin_init_workspace,如下所示:
touch( "$dir/stderr.txt" );
chmod( "$dir/stderr.txt", 0755 );
$fp = fopen("$dir/stderr.txt", "w");
fclose($fp);
$descr = array(
0 => array("pipe", 'r'), // stdin
1 => array("pipe", 'w'), // stdout
2 => array("file", "$dir/stderr.txt", "w")to file
);
$pid = proc_open( "catkin_init_workspace", $descr, $pipes, $dir );
if (!is_resource( $pid) )
throw new Exception ( "`catkin_init_workspace` exec failed");
else if ( is_resource( $pid ) )
{
fclose( $pipes[1] );
$retval = proc_close( $pid );
}
上述代码已与 CMake、GCC 和其他应用程序一起使用。 但是,当我使用 catkin_init_workspace 尝试此操作时,我得到:
sh: 1: catkin_init_workspace: not found
现在,据我了解,catkin_init_workspace 是一个 python 脚本:
/opt/ros/indigo/bin/catkin_init_workspace
我尝试使用绝对路径直接调用它,但是没有用。
作为用户,一切正常。但不是当我通过 www-data 执行时,Apache2 的用户/组设置。
ROS 教程解释了我需要通过运行设置我的环境变量
source /opt/ros/indigo/setup.bash
在调用 proc_open 之前,我也尝试过通过 PHP 执行此操作,但无济于事。 我的理解是需要正确设置环境变量。
在做
出口 | grep ROS
显示:
declare -x ROSLISP_PACKAGE_DIRECTORIES="/home/alex/Projects/ros_ws/devel/share/common-lisp"
declare -x ROS_DISTRO="indigo"
declare -x ROS_ETC_DIR="/opt/ros/indigo/etc/ros"
declare -x ROS_MASTER_URI="http://localhost:11311"
declare -x ROS_PACKAGE_PATH="/home/alex/Projects/ros_ws/src:/opt/ros/indigo/share:/opt/ros/indigo/stacks"
declare -x ROS_ROOT="/opt/ros/indigo/share/ros"
declare -x ROS_TEST_RESULTS_DIR="/home/alex/Projects/ros_ws/build/test_results"
这些是我需要为 www-data 设置的环境变量以正确调用 catkin 吗?
如果是这样,我如何将这些变量作为 env 数组传递给 PHP 的 proc_open?
【问题讨论】:
标签: php python environment-variables ros