1

I can't seem to get my python script to work when I execute it in PHP with shell_exec

I am using the virtual robot in choregraphe

Here is my code: PHP

$command = escapeshellcmd("python test.py");
$output = shell_exec ($command);
echo $output;

Python:

from naoqi import ALProxy
import os,sys
import motion

#import qi.logging
#qi.logging.setLevel(qi.logging.FATAL)

pFractionMaxSpeed=0.4
mp = ALProxy("ALMotion", "127.0.0.1",51712)
JointName = JointNames = ["LShoulderRoll","LShoulderPitch","LElbowYaw","LElbowRoll","LHand"]
Arm1 = [90,0,-90,-85,90]
Arm1 = [ x * motion.TO_RAD for x in Arm1]
mp.post.angleInterpolationWithSpeed(JointNames, Arm1, pFractionMaxSpeed)

If I just run the python through cmd, then it works fine and makes the robot move.

I think it has something to do with that it is run as the www-data user and it messes the naoqi modules up (or something along those lines): link

I am just not sure how to do it in windows with XAMPP or WAMP

1 Answers1

0

It may be that your www-data user does not have access to port 51712 (or whichever port Choregraphe's virtual nao is using - it may change between sessions, have you checked that?). Maybe you can try running telnet 127.0.0.1 51712 from your PHP code - if that doesn't work, qimessaging won't be able to connect to that port either.

Emile
  • 2,946
  • 2
  • 19
  • 22
  • I tested it out with an actual nao robot on port 9559 and it works fine. I couldn't get the telnet command to work on windows. But since it worked with the actual robot, I am guessing that the www-data user does not have access to the virtual robot port – NoobsWeStand Sep 05 '18 at 21:27
  • OK; did you check that the virtual robot's port didn't change? I think it changes each time you close and open Choregraphe. – Emile Sep 06 '18 at 16:18
  • Yes. The port stays the same. I tested the python script normally, and then I tested it with shell_exec. When I test the python normally it works, but with shell_exec it gives that error – NoobsWeStand Sep 06 '18 at 16:28