I want to get an artisan command to run a bash script when executed.
So I've created an artisan command using the following
php artisan make:command backupList --command=backup:list
And here is 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');
}
}
Run Code Online (Sandbox Code Playgroud)
In handle() exec and shell_exec don't seem to work, are there any alternatives to get the artisan command to run bash in shell?
Nir*_*hah 11
而不是使用:
$this->exec('ls -la');
Run Code Online (Sandbox Code Playgroud)
您可以简单地执行以下操作:
// execute command
exec("ls -la", $output);
// print output from command
$this->comment( implode( PHP_EOL, $output ) );
Run Code Online (Sandbox Code Playgroud)
由于 Laravel 在核心中使用 Symphony。您可以使用已经在 Laravel 中实现的 Symphony 组件。对于这种情况,您可以使用这个
http://symfony.com/doc/current/components/process.html
| 归档时间: |
|
| 查看次数: |
7053 次 |
| 最近记录: |