You can execute a command on your local machine like this:
CLI::create('path', 'user')->execute('your favorite command');
It will return an instance of Symfony's Process
.
This package is based on the spatie/ssh package please consider support them.
You can install the package via composer:
composer require spatie/ssh
You can execute an SSH command like this:
$process = CLI::create('path', 'user')->execute('your favorite command');
It will return an instance of Symfony's Process
.
If you don't want to wait until the execute commands complete, you can call executeAsync
$process = CLI::create('path', 'user')->executeAsync('your favorite command');
To check if your command ran ok
$process->isSuccessful();
This is how you can get the output
$process->getOutput();
To run multiple commands pass an array to the execute method.
$process = CLI::create('path', 'user')->execute([
'first command',
'second command',
]);
Behind the scenes all commands will be performed using Symfonys Process
.
You can configure to the Process
by using the configureProcess
method. Here's an example where we disable the timeout.
CLI::create('user', 'host')->configureProcess(fn (Process $process) => $process->setTimeout(null));
You can get notified whenever your command produces output by passing a closure to onOutput
.
CLI::create('user', 'host')->onOutput(fn($type, $line) => echo $line)->execute('whoami');
Whenever there is output that closure will get called with two parameters:
type
: this can beSymfony\Component\Process\Process::OUT
for regular output andSymfony\Component\Process\Process::ERR
for error outputline
: the output itself
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email ramon.pego.stl@gmail.com instead of using the issue tracker.
The CLI
class contains code taken from laravel/envoy
The MIT License (MIT). Please see License File for more information.