python script launch by php
<p>I'm trying to launch a python script in my php page. it seems that the python interpreter itself is correctly started as using 'python -h', I got a feedback.</p>

<p>I want to start python toto.py but nothing happens.</p>

<p>I have tried shell_exec, exec, system and popen but still nothing happend.</p>

<p>This command works fine in my linux console under bash. I do not have any errors raised when php launch the command, this is why it's difficult to debug.</p>

<p>Below is the code</p>

<p>What I have done is</p>

<p>1st try (alos done with exec_shell and system)</p>

<pre><code>exec('/usr/bin/python /home/seb/bin/scripts/toto.py'); 
</code></pre>

<p>2nd try:</p>

<pre><code>$handle = popen('/usr/bin/python /home/seb/bin/scripts/toto.py','r');
echo "'$handle'; ".gettype($handle) . "\n";
$read = fread($handle, 1048);
echo "'$read'";
pclose($handle);
</code></pre>

<p>This working fine if I try the command with '/usr/bin/python -h', I got in $read the help.</p>

<p>I have finally got more details. One of my mistakes was that the python script do not display anything, I just compute data and send it to the USB port. I have added some "print" and saw that the script is interpreted by Python but I think that the issue is more focused on the access right I had to manage to send data on the serial/USB link using a python script through an apache server. I don't know how much apache secured peripheral access.</p>

<p>That could also explain why adb command run through the php script alos not work as adb is also using the USB port to communicate.</p>

<p>I have run a whoami command in my php script bu it return "nobody" that fact is that www-data got access to my user account and also to dialout to access to tty. I do not understand why command: </p>

<pre><code>system('whoami') 
</code></pre>

<p>return nobody user as php is owned by root, user supposed to be www-data.</p>

<p>Do I have to add some specific coding word in php to define a user which is allowed to run the script ? for example, when I start my python script using</p>

<pre><code>system('/usr/bin/python /home/user/bin/toto.py');
</code></pre>

<p>in order to force this script run by a specific user. If so, what method must be used ?</p>

<p>Any idea ?</p>

<p>Seb</p>
