通过Laravel Artisan Console运行外部命令

时间:2018-01-22 23:11:53

标签: laravel console artisan

我希望从Laravel执行psexec来执行一些远程命令,我想使用Artisan控制台来执行此操作(暂时)。理想情况下,我想导航到一个网址,然后发出命令(这是我在初始阶段后实现的)。

到目前为止我所拥有的是:

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class RestartSplunk extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'splunk:restart {host}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Restart Splunk instance on given host';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $host = $this->argument('host');

        $bar = $this->output->createProgressBar();

        if ($this->confirm('Are you sure you\'d like to restart ' . $host )) {
            $this->info('Restarting ' . $host . '...');
        }
    }
}

如果有人已经实现了这个或者可以分享一些资源来实现这一点,那么我非常感激。

1 个答案:

答案 0 :(得分:0)

我找到了答案The Process Component in Symphony