通过使用PHP exec()运行Python脚本 [英] Running Python scripts from using PHP exec()

查看:297
本文介绍了通过使用PHP exec()运行Python脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在php/html文件的按钮按下事件中运行python脚本.我尝试了以下. PHP exec()是否可能?但是跟随没有奏效.我的代码有什么问题?

I want to run a python script in a button press event of a php/html file. I tried following. Is this possible with PHP exec()? But following didn't work. What is wrong with my code?

HTML文件

<html>
<head></head>
<body>
<H3>Run Python Script...</H3>
<form name="input" action="test2.php" method="get">
<input type="submit" value="Submit">
</form>
</body>
</html>

PHP exec()

PHP exec()

<html>
<head></head>
<body>
<H3>Executing...</H3>
<?php exec("first.py"); ?>
<H3>Completed...</H3>
</body>
</html>

推荐答案

即使您的python脚本也可能有几个问题.

There can be several problems with even your python script.

首先:您可以从控制台运行此脚本吗? (脚本的开头是否有#!/path/to/env/python)? 如果不是,则将其添加到脚本或exec函数中(不带#!)

First: Can you run this script from console? (Do you have a #!/path/to/env/python in the script's beginning)? If not, then either add it to your script or to the exec function (without #!)

您还可以使用passthru代替exec,以便显示脚本的原始输出.

You can also use passthru instead of exec, so you can display the raw output of the script.

这篇关于通过使用PHP exec()运行Python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆