1. Go to this page and download the library: Download ptlis/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/ */
ptlis / shell-command example snippets
use ptlis\ShellCommand\CommandBuilder;
$builder = new CommandBuilder();
use ptlis\ShellCommand\CommandBuilder;
use ptlis\ShellCommand\UnixEnvironment;
$builder = new CommandBuilder(new UnixEnvironment());
$builder->setCommand('git') // Executable in $PATH
$builder->setCommand('./local/bin/git') // Relative to current working directory
$builder->setCommand('/usr/bin/git') // Fully qualified path
$build->setCommand('~/.script.sh') // Path relative to $HOME
$builder
->addProcessObserver(
new AllLogger(
new DiskLogger(),
LogLevel::DEBUG
)
)
$command = $builder
// ...
->buildCommand();
$result = $command
->runSynchronous();
$result->getExitCode(); // 0 for success, anything else conventionally indicates an error
$result->getStdOut(); // The contents of stdout (as a string)
$result->getStdOutLines(); // The contents of stdout (as an array of lines)
$result->getStdErr(); // The contents of stderr (as a string)
$result->getStdErrLines(); // The contents of stderr (as an array of lines)
$result->getExecutedCommand(); // Get the executed command as a string, including environment variables
$result->getWorkingDirectory(); // Get the directory the command was executed in
$process = $command->runAsynchronous();
if (!$process->isRunning()) {
echo 'done' . PHP_EOL;
}