0

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
asked Aug 2, 2015 at 19:38
1
  • Thank you for your valuable inputs; they are all helpful, and solved my problem. Commented Aug 2, 2015 at 20:16

2 Answers 2

3

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
Sign up to request clarification or add additional context in comments.

Comments

1

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

answered Aug 2, 2015 at 19:39

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.