当PHP进程生成时,找不到ROS catkin_init_workspace [英] ROS catkin_init_workspace not found when spawned as process by PHP

查看:384
本文介绍了当PHP进程生成时,找不到ROS catkin_init_workspace的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我详细说明一下:我试图从PHP中生成 catkin_init_workspace ,使用 proc_open

  touch($ dir / stderr.txt); 
chmod($ dir / stderr.txt,0755);
$ fp = fopen($ dir / stderr.txt,w);
fclose($ fp);

$ descr = array(
0 =>数组(pipe,'r'),// stdin
1 =>数组(pipe w'),// stdout
2 =>数组(file,$ dir / stderr.txt,w)到文件
);

$ pid = proc_open(catkin_init_workspace,$ descr,$ pipes,$ dir);

if(!is_resource($ pid))
throw new异常(`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数据执行时,不是Apache2的用户/组设置。



ROS教程解释说,我需要设置我的环境变量,通过运行

  source /opt/ros/indigo/setup.bash 

在调用proc_open之前,我也尝试过通过PHP进行操作,但是没有效果。
我的理解是我需要正确设置环境变量。



执行


export | 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 /项目/ ros_ws / build / test_results

这些环境变量是否需要为www数据设置要正确地调用catkin?



如果是这样,我如何传递一个env数组到PHP的proc_open,这些变量?

解决方案

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



当您在PHP中执行此操作时,我猜你使用了一些额外的 proc_open exec 调用或类似的事情之前调用 proc_open(catkin_init_workspace,...)

由这样做,环境可能只是为这个单一的调用设置,并且不保存,直到您在另一个 proc_open catkin_init_workspace c> -call。



可能的解决方案



我现在无法测试这个(没有安装PHP)但是以下内容应该有效:


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

     #!/ bin / bash 
    source /opt/ros/indigo/setup.bash
    catkin_init_workspace


  2. 在PHP中,调用此脚本而不是 catkin_init_workspace


Let me elaborate: I am trying to spawn the catkin_init_workspace from PHP, using the proc_open like so:

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 );
}

The above code has worked with CMake, with GCC and other applications. However, when I try this with catkin_init_workspace, I get:

sh: 1: catkin_init_workspace: not found

Now, as far as I understand, catkin_init_workspace is a python script at:

/opt/ros/indigo/bin/catkin_init_workspace

I tried invoking it directly by using the absolute path, but that didn't work.

As a user, everything works fine. But not when I am executing via www-data, the user/group setup for Apache2.

ROS tutorial explain that I need to setup my environment variables, by running

source /opt/ros/indigo/setup.bash

Which I also tried doing via PHP, right before I invoke the proc_open, but to no avail. My understanding is that I need to setup the environment variables correctly.

Doing

export | grep ROS

shows:

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"

Are those the environment variables I need to setup for www-data to correctly invoke catkin?

If so, how do I pass as an env array to PHP's proc_open, those variables?

解决方案

As you already figured out, source /opt/ros/indigo/setup.bash has to be called in advance, otherwise your environment is not set up to find the ROS commands.

When you did this in PHP, I guess you used something like an additional proc_open or exec call or something similar before you call proc_open("catkin_init_workspace", ...)?
By doing this, the environment is probably only set up for this single call and it is not kept until you run catkin_init_workspace in another proc_open-call.

Possible Solution

I cannot test this here right now (no PHP installed), but the following should work:

  1. Create a simple bash script with the following content:

    #!/bin/bash
    source /opt/ros/indigo/setup.bash
    catkin_init_workspace
    

  2. In PHP, call this script instead of catkin_init_workspace

这篇关于当PHP进程生成时,找不到ROS catkin_init_workspace的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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