Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sogeniusio's avatar

Run CMD command via Laravel Artisan Console

I'm looking to execute psexec from Laravel to execute some remote command and I'd like to use the Artisan Console to do so (for now). Ideally, I'd like to navigate to a url and the command would be issued (something i'd implement after this initial stage).

What I have so far is:

<?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 . '...');
        }
    }
}

If someone has implemented this or can share some resources to accomplish this it'd me much appreciated.

Also found here

0 likes
4 replies
sogeniusio's avatar

Where do I write the code? For example, if I wanted to run ipconfig /all

bobbybouwmann's avatar

Yes, new Process is the way to go. However in your question you only asked about Laravel commands so that why I answered it like that!

Please or to participate in this conversation.