首页 > 解决方案 > 无法从路由运行 Laravel Artisan 命令

问题描述

我有一个可执行的 shell 文件,并且可以从 CLI 命令成功运行它,但是我在从路由运行这个工匠命令时遇到了一些问题。

当我从终端运行它时,我得到了预期的输出消息并且文件被复制,但是从路由运行它既不会在日志中显示任何内容,也不会复制文件“cp .env .env.test”。

我正在使用 laravel 5.6 并在 Mac 上的本地环境中尝试这个。

这是外壳文件(shell.sh):

#!/bin/sh

php artisan cache:clear

cp .env .env.test

这是工匠指挥部

    protected $signature = 'shell:run';


    protected $description = 'Run sheel file';


    public function __construct()
    {
        parent::__construct();
    }


    public function handle()
    {
        $output = shell_exec('./shell.sh');

        $this->info($output);
    }

和路线:

    Route::get('/shell', function () {
        Artisan::call('shell:run');
    });

标签: phplaravellaravel-5.6

解决方案


推荐阅读