0

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?

3

2 Answers 2

0

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');
Sign up to request clarification or add additional context in comments.

6 Comments

It tells me "io.UnsupportedOperation: not writable" when i execute the file with the cmd
can you just echoes a value in your genereBonDeCommande.py to test where is the problem? Because maybe the error is in this file
The problem is that it doesn't want to write into the file. If i put fichier.read() instead it works properly.
@guillaumedrillaud then your question "Then how can I call a Python file from within PHP?" is solved the problem is other
I don't know if it works because if i put fichier.read() there is no error but i don't know if the call worked or not. How can I check if the call worked ?
|
0

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");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.