3

I'm trying to run a ROS shell program on the server through php on Ubuntu 14.04. I have tried using system, exec, shell_exec but nothing happens and I don't get any output. The system call is the following:

echo shell_exec("/opt/ros/indigo/bin/rosrun gazebo_ros spawn_model -database Part_A -gazebo -model Part_A");

What are the limitations of using system or exec to run any shell command through php on a server?

I don't care as much about the output of the command as for its execution. I think the problem has to do with the fact that PHP doesn't have any PATH like shell does so it can't find any applications without specifying the exact location. How can I make PHP se the same PATH shell does?

pap-x
  • 564
  • 1
  • 8
  • 15
  • Possible duplicate of [PHP reading shell\_exec live output](http://stackoverflow.com/questions/20107147/php-reading-shell-exec-live-output) – slbteam08 Feb 03 '16 at 13:01
  • @slbteam08 No, I don't care about the output so much, I just want to run this command. – pap-x Feb 03 '16 at 13:06
  • Did you make sure that the `setup.bash` is sourced? Otherwise `rosrun` won't find the package. – luator Feb 03 '16 at 15:11
  • See also [my answer to this similar question](http://stackoverflow.com/questions/30340534/ros-catkin-init-workspace-not-found-when-spawned-as-process-by-php/30350482#30350482) – luator Feb 03 '16 at 15:16
  • @luator I tried sourcing it but I get many errors: sh: 1: /opt/ros/indigo/setup.bash: Bad substitution sh: 7: /opt/ros/indigo/setup.bash: builtin: not found sh: 8: .: Can't open /setup.sh – pap-x Feb 04 '16 at 08:40
  • 1
    Solved it! Instead of using setup.bash I used setup.sh – pap-x Feb 04 '16 at 09:05
  • Good to hear :). So you managed to source it from within PHP? If it solves your problem, it would be nice if you post an answer to your question, saying what exactly you did to make it run. – luator Feb 04 '16 at 11:10

1 Answers1

1

The problem was that the apache user and the environment in which the bash commands are running are not set up correctly. I followed the instructions from this answer but instead of using "source" I used "." and instead of using the source.bash file I used the source.sh file. I also set all the environment variables that had to do with ros or gazebo using the putenv() function.

Community
  • 1
  • 1
pap-x
  • 564
  • 1
  • 8
  • 15