【发布时间】:2019-05-27 22:04:41
【问题描述】:
我正在从 PHP 运行许多 python 脚本。我的 php 脚本模板如下:
<?php
setlocale(LC_ALL, "en_US.utf8");
header("Content-Type: application/json");
header("Access-Control-Allow-Origin: *");
$command = escapeshellcmd("/usr/bin/python2.7 /path/to/script");
$args = escapeshellarg($_GET["title"]). " " .
escapeshellarg($_GET["user"]);
$output = shell_exec($command . " " . $args);
echo $output;
但现在我需要在虚拟环境中运行一些 python 脚本。
我尝试将/usr/bin/python2.7 替换为./www/python/venv/bin/python3,但它不起作用。
那么如何在 PHP 中运行它呢?
【问题讨论】:
-
请解释一下“但它不起作用”是什么意思。
-
表示Python脚本没有运行。
-
您是否收到错误消息?如果是,是哪一个?