Erron
Erron

Reputation: 11

Python issue passing multiple arguments

Im new to python and trying to pass 2 variables from PHP to Python. I can get one to pass no problem (with spaces in the string) but when i try to read a second in sys.argv it fails.

the PHP is as follows:

$wt = "yes it worked woot";
$wt = str_replace(" ","\ ",$wt);
$pn = "42";
ob_start();
passthru('/usr/bin/python2.7 /var/www/cronjobs/test.py ' . "$pn " . "$wt");
$output = ob_get_clean();

The in test.py i have:

import sys

id = sys.argv[1]
text = sys.argv[2]

if i remove the sys.argv[2] line it works fine, i can even pass the string with spaces by itself.

cant see what im doing wrong.

Upvotes: 0

Views: 52

Answers (1)

user764357
user764357

Reputation:

You are escaping the strings on this line:

$wt = str_replace(" ","\ ",$wt);

Which means there is no second argument. Stop escaping the strings, and it should work.

Upvotes: 1

Related Questions