Command abstraction class that allows running any command with a given set of arguments.
Usage examples:
Run ls -l -a in the current directory
$command = new \Clinner\Command\Command(
'ls',
array('-l', '-a')
);
$command->run();
echo $command->getExitCode();
echo $command->getOutput();
This example is equivalent to the one above
$command = \Clinner\Command\Command::create(
'ls',
array('-l', '-a')
)
->run();
echo $command->getExitCode();
echo $command->getOutput();
You can also pipe commands, just like in a command-line interface:
use \Clinner\Command\Command;
$grepCommand = Command::create(
'grep',
array('-v' => '^#'),
array('delimiter' => ' ')
);
$cutCommand = Command::create(
'cut',
array('-d' => ':', '-f' => 1),
array('delimiter' => '')
);
$systemUsers = Command::create(
'cat',
array('/etc/passwd')
)
->pipe(
$grepCommand->pipe(
$cutCommand
)
)
->run()
->getOutputAsArray("\n");
This class may take the following options:
* delimiter (string): A string that will be put in key-value pairs of arguments to separate the key
from its value. Defaults to '='.