3

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
1
  • In PHP, the string concatenation operator is ., not +. Commented Feb 14, 2011 at 20:48

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.