Reputation: 623
I am trying to execute a cgi/python script from within php, and at the same time pass the cgi/python script a paramter.
in my php I have
<? echo exec('/var/www/cgi-bin/test.cgi ' + $_POST["var"]); ?>
However it doesn't work, and in the apache log it says 'sh:0 not Found'
This test script is very simple :
#!/usr/bin/python
import cgi, sys, os
for arg in sys.argv:
print arg
Upvotes: 3
Views: 1910
Reputation: 4688
As someone pointed out, the string concatenation operator in PHP is .
, not +
.
The result of "adding" non-numeric strings is 0. That's why the shell tries to run the command "0" and returns error: "sh:0 not found".
Try this:
exec('/var/www/cgi-bin/test.cgi ' . escapeshellcmd($_POST["var"]));
Also, note that shell command arguments should be escaped with escapeshellcmd.
Upvotes: 2