Exécution python depuis php avec création de fichier
Bonjour et joyeux noël :)
Voilà mon petit problème:
depuis une page web en php je lance un script python sur une machine distante (à savoir un Raspberry Pi 2 sous Raspian Jessie avec Nginx et PHP 5).
dans le script python je récupère une variable transmise par le script php, variable que je veux enregistrer dans un fichier.
le script python fonctionne bien quand je lance en local sur le Raspberry Pi.
Depuis le web le script python se lance bien mais le fichier n'est jamais créé ?
je ne comprends pas pourquoi.
voici les deux scripts:
script PHP: index.php
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| <h2>Chauffage</h2>
<form action="index.php" method="post">
<label for="Consigne"> Nouvelle Consigne</label>: <input type="text" name="Consigne" id="Consigne" size="4">
°C
<input type="Submit" value="Valider">
</form>
<br>
<?php
if (!empty($_POST["Consigne"])) {
$param=$_POST['Consigne'];
$req = shell_exec("sudo /usr/bin/python /home/lologramme/Documents/www/test.py $param");
echo $req;
echo "ok";
}
?>
<h3>Fin</h3> |
et le code Python; test.py
Code:
1 2 3 4 5 6 7 8 9 10 11
| #!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import pickle
parametre = sys.argv[1]
fichier=open('para.txt','wb')
pickle.dump(parametre,fichier)
fichier.close() |
quelqu'un aurait il une idée sur ce problème;
par avance merci