【问题标题】:ROS catkin_init_workspace not found when spawned as process by PHPROS catkin_init_workspace 由 PHP 作为进程生成时未找到
【发布时间】: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


    【解决方案1】:

    如您所见,source /opt/ros/indigo/setup.bash 必须提前调用,否则您的环境未设置为查找 ROS 命令。

    当您在 PHP 中执行此操作时,我猜您在调用 proc_open("catkin_init_workspace", ...) 之前使用了额外的 proc_openexec 调用或类似的调用?
    通过这样做,环境可能只为这个单一调用设置,并且在您在另一个 proc_open-call 中运行 catkin_init_workspace 之前不会保留它。

    可能的解决方案

    我现在无法在这里测试(没有安装 PHP),但以下应该可以:

    1. 创建一个包含以下内容的简单 bash 脚本:

      #!/bin/bash
      source /opt/ros/indigo/setup.bash
      catkin_init_workspace
      
    2. 在 PHP 中,调用此脚本而不是 catkin_init_workspace

    【讨论】:

    • 是的,这是有道理的。我使用 shell_exec 调用 setup.bash 脚本,然后使用 proc_open 调用 catkin_init_workspace。我想一种解决方案是按照您的建议进行操作,但老实说,我更愿意知道如何为 proc_open 设置环境,因为它可以让我对生成的进程进行大量控制。
    • @Alex:我明白你的意思。也许有可能在启动 apache 之前以某种方式为 www-data 用户获取setup.bash。不过,我不得不承认我不知道如何做到这一点。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-11
    • 1970-01-01
    • 2014-09-01
    相关资源
    最近更新 更多