So first off, sorry if this question has already been answered elsewhere, but I couldn't find the answer myself.
I've got a LAMP server running in Ubuntu 16.04 and I'm trying to use Python 2.7.12 to write to a text file from PHP.
I've got the following two files (note, these two files are in the same directory):
index.php
<?php
$command = escapeshellcmd('python test.py a b c');
$output = shell_exec($command);
echo $output;
?>
test.py
import sys
print "argv1: ", sys.argv[1]
print "argv2: ", sys.argv[2]
print "argv3: ", sys.argv[3]
f = open("test-" + sys.argv[1] + ".txt","w+")
f.write("test")
f.close()
print "Text added."
When I navigate to the index.php file in my browser, I get the following output:
argv1: a argv2: b argv3: c
However, when I execute this code in the terminal the file test-a.txt is created and I get the following output:
layer8@alpha:/var/www/html/$ python test.py a b c
argv1: a
argv2: b
argv3: c
Text added.
I can't seem to understand and work out why the Python file isn't executing any code past the third print argv3 statement?
I've done a lot of research into this and I've been unable to find a solution. If you need any further information from me, please do not hesitate to ask; any responses are appreciated.
Thanks.