PHP code example of artarts36 / shell-command

1. Go to this page and download the library: Download artarts36/shell-command library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

artarts36 / shell-command example snippets


use ArtARTs36\ShellCommand\ShellCommand;

$command = ShellCommand::make('git')->addArgument('push')->addOption('force');

var_dump($command->__toString()); // git 'push' --force 2>&1

use ArtARTs36\ShellCommand\ShellCommand;

$command = ShellCommand::make('git')->addArgument('pull');
$result = $command->execute();

var_dump($result->getCommandLine());
var_dump($result->getCode());
var_dump($result->getDate());
var_dump($result->getResult());
var_dump($result->getError());

$connection = \ArtARTs36\ShellCommandSshExecutor\SSH\Connection::withPassword(
    'remote.host',
    'user',
    'password'
);

$command = \ArtARTs36\ShellCommand\ShellCommand::make('ls');

$command->setExecutor(new \ArtARTs36\ShellCommandSshExecutor\SshCommandExecutor($connection));

var_dump($command->getShellResult());


$executor = new \ArtARTs36\ShellCommand\Executors\TestExecutor();

$command = new \ArtARTs36\ShellCommand\ShellCommand('reboot');

$executor->addSuccess('OK');

$command->execute($executor);