我正在尝试从laravel运行python脚本。我正在使用版本dpi
。
在控制器中,我有这个
figure
但是它返回了我5.6
。
输出应为public function test_python()
{
$command = escapeshellcmd('python ' . public_path() . '\test\test.py');
$output = shell_exec($command);
dd($output);
}
null
如果使用此方法在我的laravel文件夹之外创建一个php文件
Hello World!
当我从命令行运行#!/usr/bin/env python
print('Hello World!')
时,我看到了正确的结果。
<?php
$command = escapeshellcmd('python C:\wamp64\www\projects\laravel\public\test\test.py');
$output = shell_exec($command);
echo $output;
具有正确的权限(php path/outside/laravel/test.php
)。而且python在环境路径方面也是正确的。
我也尝试使用脚本的完整路径,但是仍然失败。
PS:this post的答案对我不起作用
答案 0 :(得分:0)
首先,也许“ php用户”没有运行权限?我说PHP看不到全局路径变量。
此外,您可以为其使用Symfony \ Proccess库