2017-09-14 983 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