从PHP中调用Python文件

2024-05-04 13:35:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我想从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文件呢?你知道吗


Tags: 文件pyfilesopenprogramexedevserverexec
2条回答

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

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

如果文件不存在,则创建一个文件;如果文件确实存在,则重写

而不是这个:

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

相关问题 更多 >