Laravel 5 - 如何创建 Artisan 命令来执行 bash 脚本

2024-03-04

我想获得一个 artisan 命令来在执行时运行 bash 脚本。

所以我使用以下命令创建了一个 artisan 命令

php artisan make:command backupList --command=backup:list

这是 backupList.php

<?php

namespace App\Console\Commands;

require_once __DIR__ . '/vendor/autoload.php'; 

use Illuminate\Console\Command;


class backupDB extends Command
{

protected $signature = 'backup:list {name}';

protected $description = 'Database backup tool';



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



public function handle()
{
    $this->exec('ls -la');
}
}

在handle()中,exec和shell_exec似乎不起作用,是否有其他方法可以让artisan命令在shell中运行bash?


而不是使用:

$this->exec('ls -la');

您可以简单地执行以下操作:

// execute command
exec("ls -la", $output);

// print output from command
$this->comment( implode( PHP_EOL, $output ) );
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Laravel 5 - 如何创建 Artisan 命令来执行 bash 脚本 的相关文章

随机推荐