user3668629
user3668629

Reputation: 113

Passing PHP variable into a Python script not working

I am trying to call a simple python script from a php script. The result I am getting is just a single word while my actual input is a long text/sentence. The php script should return the entire sentence; it currently outputs only "The"

Python script

import sys
print sys.argv[1]

Php script

$var1 = "The extra sleep will help your body wash out stress hormones.";
$output = exec("C:\Python27\python.exe example.py $var1");
echo $output;

Upvotes: 0

Views: 165

Answers (2)

IanPudney
IanPudney

Reputation: 6021

Because command line parameters are space-delimited, you have to add some quotes:

$output = exec("C:\Python27\python.exe example.py \"$var1\"");

Upvotes: 3

Daniel Roseman
Daniel Roseman

Reputation: 599620

Your Python script is printing the first parameter that it receives. That first parameter is "The".

Upvotes: 1

Related Questions