首页 > 解决方案 > 如何运行要求在 php 中输入的 python 脚本

问题描述

我想要一种将输入从 PHP 传递到 python 脚本的方法。我正在使用以下命令,但似乎无法找到将值传递给脚本的方法

$command = escapeshellcmd('/usr/custom/test.py');
$output = shell_exec($command);

标签: phppython

解决方案


例如,您有一个像这样的简单输入:

<input type="text" name="name"><br>

要通过它,您可以简单地这样做:

<?php system("python mycode.py ".$_POST["name"]); ?>

你也可以使用exec()passthru()

system("python mycode.py <arg1> <arg2>");

//or

exec("python mycode.py <arg1> <arg2>");

//or

passthru("python mycode.py <arg1> <arg2>");

玩的很开心 !


推荐阅读