Like the file says I am executing a python script from a PHP file sitting on my apache webserver. The example I have is extremely basic.
PHP file — test.php
<?php
echo "hello";
echo exec("/usr/local/bin/python2.7 test1.py");
?>
python script — test1.py
print "world"
fh = open ('testtest' ,'r')
for line in fh:
print line
contents of — testtest
abcdefg
‘world’ prints when I don’t have the bottom 2 lines of test1.py but it stops printing as soon as I add for line in file: Thank you.
Edit: I’m trying to print the contents of testtest.
exec does not do what you expect it to do. The documentation states that it only returns the last line of output. It recommends use of passthru instead.