I have a php file in my XAMPP-VM server which looks like this:
<?php
$message = exec('python testPython.py');
echo($message);
?>
the testPython.py file looks like this:
f = open('data.txt', 'w+')
f.write('test')
print('hello')
f.close()
When I run the php file like so localhost/testPHP.php, the testPython.py file gets stuck on line one and does not move on. When I commented out the first, second, and last line of code, the program worked fine and printed out "hello." Interestingly, when I run the testPython.py file from terminal like this python testPython.py
it works. It opens data.txt and writes "test." Does anyone know how I could fix this problem?
note: I know that I could easily do the same thing from php without executing a python file at all but this post is just showcasing my problem. I need to open a file in a python file that I have already put a lot of work into.