Python script in php ausführen
Verfasst: Dienstag 12. Dezember 2017, 16:44
Hallo zusammen,
mein aktuelles Problem treibt mich jetzt seit Tagen in den Wahnsinn...
Folgend mein Setup welches soweit vollständig funktioniert:
- ich rufe über eine URL ein PHP Skript auf, welches über exec() ein Python Skript auf einem Raspberry Pi ausführt
- das Python Skript macht ein Foto und schreibt die Bilddatei auf ein NAS
Nun zum Problem:
- in einem anderen PHP Skript (mount.php) versuche ich auch über exec() ein anderes Python Skript (start.py) auszuführen
mount.php
<?php
echo exec("sudo python /var/www/html/start.py 2>&1", $output);
?>
start.py
#!usr/bin/env python
from subprocess import *
check_call( 'sudo mount -t cifs //rasp-ip/photo /home/NAS2 -o user=pi,pass=pass', shell=True )
- Python Skript direkt über die Shell ausgeführt - funktioniert
- PHP Skript über die Shell ausgeführt - funktioniert
- PHP Skript über den Browser ausgeführt - funktioniert nicht, obwohl es grundsätzlich wie oben beschrieben mit PHP und Python Aufruf funktioniert
- alle Dateien liegen im /var/www/html Verzeichnis des Pi's und besitzen identische Rechte
Der exec() output liefert folgende Fehlermeldung:
subprocess.CalledProcessError: Command 'sudo mount -t cifs //rasp-ip/photo /home/NAS2 -o user=pi,pass=pass' returned non-zero exit status 32mountArray ( [0] => mount error(16): Device or resource busy [1] => Refer to the mount.cifs(8) manual page (e.g. man mount.cifs) [2] => Traceback (most recent call last): [3] => File "/var/www/html/start.py", line 5, in [4] => check_call( 'sudo mount -t cifs //rasp-ip/photo /home/NAS2 -o user=pi,pass=pass', shell=True ) [5] => File "/usr/lib/python2.7/subprocess.py", line 186, in check_call [6] => raise CalledProcessError(retcode, cmd) [7] => subprocess.CalledProcessError: Command 'sudo mount -t cifs //rasp-pi/photo /home/NAS2 -o user=pi,pass=pass' returned non-zero exit status 32 )
Wo liegt das Problem?
Vielen Dank für jegliche Lösungsvorschläge!
mein aktuelles Problem treibt mich jetzt seit Tagen in den Wahnsinn...
Folgend mein Setup welches soweit vollständig funktioniert:
- ich rufe über eine URL ein PHP Skript auf, welches über exec() ein Python Skript auf einem Raspberry Pi ausführt
- das Python Skript macht ein Foto und schreibt die Bilddatei auf ein NAS
Nun zum Problem:
- in einem anderen PHP Skript (mount.php) versuche ich auch über exec() ein anderes Python Skript (start.py) auszuführen
mount.php
<?php
echo exec("sudo python /var/www/html/start.py 2>&1", $output);
?>
start.py
#!usr/bin/env python
from subprocess import *
check_call( 'sudo mount -t cifs //rasp-ip/photo /home/NAS2 -o user=pi,pass=pass', shell=True )
- Python Skript direkt über die Shell ausgeführt - funktioniert
- PHP Skript über die Shell ausgeführt - funktioniert
- PHP Skript über den Browser ausgeführt - funktioniert nicht, obwohl es grundsätzlich wie oben beschrieben mit PHP und Python Aufruf funktioniert
- alle Dateien liegen im /var/www/html Verzeichnis des Pi's und besitzen identische Rechte
Der exec() output liefert folgende Fehlermeldung:
subprocess.CalledProcessError: Command 'sudo mount -t cifs //rasp-ip/photo /home/NAS2 -o user=pi,pass=pass' returned non-zero exit status 32mountArray ( [0] => mount error(16): Device or resource busy [1] => Refer to the mount.cifs(8) manual page (e.g. man mount.cifs) [2] => Traceback (most recent call last): [3] => File "/var/www/html/start.py", line 5, in [4] => check_call( 'sudo mount -t cifs //rasp-ip/photo /home/NAS2 -o user=pi,pass=pass', shell=True ) [5] => File "/usr/lib/python2.7/subprocess.py", line 186, in check_call [6] => raise CalledProcessError(retcode, cmd) [7] => subprocess.CalledProcessError: Command 'sudo mount -t cifs //rasp-pi/photo /home/NAS2 -o user=pi,pass=pass' returned non-zero exit status 32 )
Wo liegt das Problem?
Vielen Dank für jegliche Lösungsvorschläge!