2017-09-14 29 views
0

我想获得一个artisan命令来在运行时运行bash脚本。Laravel 5 - 如何创建一个Artisan命令来执行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'); 
} 
} 

在手柄()exec和了shell_exec似乎不工作,有没有其他办法可以让手工命令在shell中运行bash?

回答

1

不是使用:

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

您只需做到以下几点:

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

// print output from command 
$this->comment(implode(PHP_EOL, $output)); 
+0

这做到了:d你真棒。谢谢! – jukerok