Reputation: 852
I'm having a problem on passing the parameters from php to python.
By using the $_SERVER['QUERY_STRING'].
http://www.domain.com/path?a_num=123&msg=hello
i will put the a_num=123&msg=hello to a variable
$a = $_SERVER['QUERY_STRING'];
system("python python.py ".$a);
and in python will print it
a = sys.argv[1]
print a
and the result is *a_num=123* only
what is the problem?
Upvotes: 0
Views: 69
Reputation: 3209
I don't think this is a problem with PHP, more how the system command is being executed. Assuming you are using Linux, the '&' character in the command:
python python.py a_num=123&msg=hello
Is being interpreted as a control operator. From the documentation for bash (although this applies equally to other shells such as tcsh):
If a command is terminated by the control operator &, the shell executes the command in the background in a subshell. The shell does not wait for the command to finish, and the return status is 0.
To prevent this, you need to quote the string being passed:
python python.py "a_num=123&msg=hello"
Which in PHP would look like:
system("python python.py \"".$a."\"");
Upvotes: 1