1

i run the python script bellow in the command line and it works fine, but when i execute it in a php file it returns an empty array.

python

import sys

id_input=sys.argv[1] 

print id_input

php

<?php


$out="";
exec("python teste.py a  ",$out);
print_r($out);

?>

output of php: array()

output in command line: a

Both files are in the same directory and i am using XAMPP in Vista OS to run them.

5
  • 1
    Try using the full path to python, not sure where that would be in Vista Commented Feb 22, 2015 at 23:47
  • it worked ! Should i always write the full path in php files? Commented Feb 22, 2015 at 23:50
  • 1
    For most things, yes. PHP isn't aware of the environment variables, it's the same in Linux too Commented Feb 22, 2015 at 23:52
  • Didn't know. I think this will be an important post for beginners in php-python. Commented Feb 22, 2015 at 23:52
  • Added as an answer then Commented Feb 22, 2015 at 23:54

1 Answer 1

2

As per comments... the problem was that you need to specify the full path to the python binary, because PHP is not aware of the environmental variables such as PATH

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.