0

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!

All I'm doing in PHP is:

 $output = exec("python path/script.py")
 echo $output;

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!

MasterWizard
  • 857
  • 2
  • 15
  • 44
  • can you obtain any error? try to find if there is an exception that causes an issue - something like: try: get = rospy.get_param("param") except BaseException as e: # save e to file <\code> – Iliyan Bobev Jan 21 '16 at 09:06
  • `rospy` doesn't seem like it's been initialized before, should it be `roslib.rospy` or `roslib`? I don't know anything about the library, but I guess that might be the error. – ishaan Jan 21 '16 at 09:07
  • @ishaan this is the way the library is imported, as I already stated, this code works perfectly on its own when I run it, however it doesnt work when I run it from PHP. – MasterWizard Jan 21 '16 at 09:11
  • @IliyanBobev I get a blank document, i tested to see if it logs errors, it does log errors when I remove both roslib, and rospy, when they are imported nothing works. – MasterWizard Jan 21 '16 at 09:33
  • Sorry, I couldn't format code in the comment; Just place the `get = rospy.get_param("param")` in try-except. In the try section, attempt to save the value of get to text file, and in the except section attempt to catch the exception details and save those to a file. This way you'll have a log. – Iliyan Bobev Jan 21 '16 at 09:36
  • this is what I did, still its blank, nothing is written when the library is imported, I only start getting error logged when the "import rospy" is not here. – MasterWizard Jan 21 '16 at 09:39

1 Answers1

1

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

Community
  • 1
  • 1
MasterWizard
  • 857
  • 2
  • 15
  • 44
  • Thank you for this answer! However I didn't understand how you add those environment variables for this particular case... Can you be more specific? (I know it's an old question) – zppinto Jan 15 '19 at 19:58