gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 15:19:49 25 4
gpt4 key购买 nike

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

所以我使用以下命令创建了一个工匠命令
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 ) );

关于ubuntu - Laravel 5 - 如何创建一个 Artisan 命令来执行 bash 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46208801/

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