Executing Python Script with PHP Variables

Thank you for your contributions. I have figured out my problem with this simple fix:

$command = 'python wordgame2.py ' . $start_word . ' ' . $end_word;
$output = passthru($command);

In order for passthru to properly handle the php variables, it needs to be concatenated into the string before executing.


Update -

Now that I am aware of PHP, the mistake lies in using the single-quotes '. In PHP, single quoted strings are considered literals, PHP does not evaluate the content inside it. However, double quoted " strings are evaluated and would work as you are expecting them to. This is beautifully summarized in this SO answer. In our case,

$output = passthru("python wordgame2.py $start_word $end_word");

would work, but the following won't -

$output = passthru('python wordgame2.py $start_word $end_word');

Original answer -

I think the mistake lies in

$output = passthru("python wordgame2.py $start_word $end_word");

Try this

$output = passthru("python wordgame2.py ".$start_word." ".$end_word);