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;
phts
3,9251 gold badge22 silver badges31 bronze badges
-
Thank you for your valuable inputs; they are all helpful, and solved my problem.user3668629– user36686292015年08月02日 20:16:27 +00:00Commented Aug 2, 2015 at 20:16
2 Answers 2
Because command line parameters are space-delimited, you have to add some quotes:
$output = exec("C:\Python27\python.exe example.py \"$var1\"");
answered Aug 2, 2015 at 19:44
IanPudney
6,0911 gold badge26 silver badges41 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Your Python script is printing the first parameter that it receives. That first parameter is "The".
answered Aug 2, 2015 at 19:39
Daniel Roseman
602k68 gold badges911 silver badges924 bronze badges
Comments
default