Calling Python file from within PHP

133 views Asked by At

I would like to call a Python file from within PHP. I've tried this :

exec('C:\Python34\python.exe ./python/genereBonDeCommande.py');

But it doesn't work. In my Python file I've got this :

fichier = open(repertoire+"C:/Program Files/EasyPHP-DevServer-14.1VC9/data/localweb/projects/Administration/bonsDeCommandes" + nom_fichier, "No13");
fichier.write('hello');

Then how can I call a Python file from within PHP?

2

There are 2 answers

0
Saroten On BEST ANSWER

Here is the solution, to create a file there is to put this line :

fichier = open("C:/Program Files/EasyPHP-DevServer-14.1VC9/data/localweb/projects/Administration/bonsDeCommandes/No15.txt","w");

w creates a file if it doesn't exist already and write over if it does exist

instead of this one :

fichier = open(repertoire+"C:/Program Files/EasyPHP-DevServer-14.1VC9/data/localweb/projects/Administration/bonsDeCommandes" + nom_fichier, "No13");
6
Adrian Cid Almaguer On

Try executing your script with the full path to your file like this:

<php
//If your file is in C:\wamp\www\python
exec('C:\Python34\python.exe C:\wamp\www\python\genereBonDeCommande.py');