I want to run python script from php.
this is my python code. It is saved in /home/pi and name of file is hello.py
#! /usr/bin/python
import bluetooth
bd_addr="xx:xx:xx:xx:xx:xx"
port=1
sock=bluetooth.BluetoothSocket(bluetooth.RFCOMM)
sock.connect((bd_addr.port))
data=""
while 1:
try:
data +=sock.recv(1024)
data_end=data.find('
')
if data_end!=-1:
rec=data[:data_end]
print datas
data=data[data_end+1:]
except KeyboardInterrupt:
break
And here is my php code. It is saved in /var/www/html and name of file is php.php
<?php
$output=shell_exec('ls -l /home/pi/hello.py');
echo "<pre>$output</pre>";
?>
And I insert localhost/php.php in chrome, it displays
-rw-r-r- 1 pi pi 378 Mar 8 12:07 /home/pi/hello.py
what is the problem??
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…