Problem in calling Python script from PHP
<p>This is my python script which creates a "test.txt" file when executed. when I execute using terminal (Ubuntu 11.04) <code>root@gml-VirtualBox:/var/www/HMS# python test.py</code>. It creates the "test.txt" in the <code>/var/www/HMS</code> directory as I expected.</p>

<pre>
test.py:

#!/usr/bin/env python

def init():
    filename = "test.txt"
    file = open(filename, 'w')
    file.write("This is the new content of test.txt :-)")
    file.close()
    print "done"

def main():
    init()

if __name__ == '__main__':
    main()
</pre>

<p>But when I try to call this test.py using PHP, It's not creating the 'test.txt' output file. </p>

<pre>
index.php:

$tmp = exec("python test.py");
echo "temp: $tmp";

</pre>

<p>Both <code>test.py</code> &amp; <code>index.php</code> are in the same directory(<code>/var/www/HMS/</code>). But when I modified the <code>test.py</code> like this:</p>

<pre>
#!/usr/bin/env python

def init():
    print "done"

def main():
    init()

if __name__ == '__main__':
    main()

</pre>

<p>It prints <code>temp: done</code> in the browser, which is what I expected. </p>

<p>I don't know why my previous python code didn't work as expected.</p>
