0

I'm a noob so bear wtih me... I have ran into an issue where my Python script, which I start from Apache server by PHP, ignores all other arguments except the first one.

PHP GETS variables and uses them as arguments when starting the script like so:

echo exec( "sudo python3 /var/www/html/motor_arg.py $n1 $t1 $n2 $t2" );

The Python srip starts but everything except $n1 is ignored and the scrip ends. When I run the script from shell like so: python3 motor_arg.py 10 5 20 5 it works just fine...

I honestly have no idea why this happens. Any help is much appreciated.

1 Answers1

0

HTTP GET request variables end up in a "superglobal". You most likely need something like this: $n1 = $_GET['n1'] or $n1 = $_REQUEST['n1']. I hope you really trust anyone making requests to this server.

You're also going to run into issues with exec('sudo'). There are some answers here, also very insecure. sudo in php exec()

Pete
  • 1,305
  • 1
  • 12
  • 36
  • I didn't mention it bu I am using `$n1 = $_GET['n1']`. Security is not at all a priority on this project. – Jakub Horník Jan 22 '20 at 00:19
  • you say `$n1` comes through, but the rest do not? I would try echoing back your variables or even exec("echo $n1 $t1 $n2 $t2 > test.txt") and see if they are being properly initialized – Pete Jan 22 '20 at 00:52