php - 如何运行要求在 php 中输入的 python 脚本
问题描述
我想要一种将输入从 PHP 传递到 python 脚本的方法。我正在使用以下命令,但似乎无法找到将值传递给脚本的方法
$command = escapeshellcmd('/usr/custom/test.py');
$output = shell_exec($command);
解决方案
例如,您有一个像这样的简单输入:
<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>");
玩的很开心 !
推荐阅读
- android - MVP 架构
- sql - 您如何并排“加入”多个 SQL 数据集(彼此不链接)?
- javascript - 为什么无阻塞节点会减少 I/O 总时间?
- scala - circe 自动推导 - 与进口作斗争
- javascript - 在 url (Javascript) 上添加部分时无法识别 Cookie
- mysql - 是否可以从 MYSQL 中的存储过程中返回多个表
- c# - 等效于 php 中的 C# Encoding.UTF8.GetBytes
- javafx - 重置无限 JavaFX RotateTransition
- ruby-on-rails - Ruby on Rails 控制器实例变量未共享
- functional-programming - 如何使用 [@ocaml.warning "-30"] 隐藏警告 30