从 PHP 中调用 Python 文件

Calling Python file from within PHP

我想从 PHP 中调用一个 Python 文件。 我已经试过了:

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

但是没用。 在我的 Python 文件中,我有这个:

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

那么如何从 PHP 中调用 Python 文件?

尝试使用文件的完整路径执行脚本,如下所示:

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

这是解决方案,要创建一个文件,请输入以下行:

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

w 如果文件不存在则创建一个文件,如果存在则覆盖

而不是这个:

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