gpt4 book ai didi

php - 如何使用 Laravel 的 command fire 方法运行 python 脚本?

转载 作者:太空宇宙 更新时间:2023-11-04 01:09:08 24 4
gpt4 key购买 nike

我需要从 Laravel 命令执行 Python 脚本,但我在 Illuminate\Console\Command 中找不到任何方法来完成我的任务。

我想通过控制台运行这个命令:

C:\Python34\python H:\myapp\app\python\questionPopulator.py

为此,我在命令 fire() 方法中尝试了以下操作:

public function fire()
{
$this->call('C:\Python34\python H:\myapp\app\python\questionPopulator.py');
}


public function fire()
{
$this->line('C:\Python34\python H:\myapp\app\python\questionPopulator.py');
}

它们都不起作用,因为 Laravel 期望我从它们调用另一个 Laravel 命令。通过 Laravel 命令调用简单 python 脚本的最佳方式是什么?

最佳答案

尝试 PHP 执行函数:http://php.net/manual/en/function.exec.php

exec('C:\Python34\python H:\myapp\app\python\questionPopulator.py');

关于php - 如何使用 Laravel 的 command fire 方法运行 python 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28758617/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com