简体   繁体   English

我可以从php调用python脚本或函数吗?

[英]Can I call python script or function from php

I have the php page which lists the backups with filename and username. 我有一个php页面,其中列出了带有文件名和用户名的备份。 the backups are done with python script but for web interface I used php. 备份是用python脚本完成的,但对于web界面,我使用的是php。

Now I want to put the facility on webpage where there will be button called restore next to backup file name and all the home dir contents are replaced. 现在我想把设施放在网页上,在备份文件名旁边会有一个名为restore的按钮,所有的主目录内容都会被替换。

I can make the python function with parameters like backup filename , username and it restores the backup. 我可以使用备份文件名,用户名等参数创建python函数,并恢复备份。

But I don't know how can I pass variables to python via php 但我不知道如何通过php将变量传递给python

Yes you can call exec("python pythonscript.py someparams"); 是的你可以调用exec("python pythonscript.py someparams"); or if you need to save the output to a variable use this code 或者如果需要将输出保存到变量,请使用此代码

exec("python mypythonscript.py someparams",$output);
var_dump($output);

More informaiton: call python script by php and solve errors 更多信息: 通过php调用python脚本并解决错误

You can call the shell from PHP: 你可以从PHP调用shell:

and there are more. 而且还有更多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM