An open API service indexing awesome lists of open source software.

https://github.com/crit/php-exec-jobs

Execute shell scripts in order with named arguments and error checking.
https://github.com/crit/php-exec-jobs

php shell

Last synced: 5 months ago
JSON representation

Execute shell scripts in order with named arguments and error checking.

Awesome Lists containing this project

README

          

# php-exec-jobs

Execute shell scripts in order with named arguments and error checking.

## Installation

`composer require crit/php-exec-jobs`

## Reason

You can accomplish something similar to this library by executing the following code for simple use cases:

```php
'
// $job->setArgWrapper(':', ':');

// optionally change the shell working directory
// defaulted to the current working directory of the PHP process
// $job->setWorkingDirectory('/sbin');

// optionally set ENV variables for this job
// $job->setEnv('CUSTOM1', 'special-value-1');
// $job->setEnv('CUSTOM2', 'special-value-2');

$job->arg('firstname', $_GET['firstname']); // John
$job->arg('lastname', $_GET['lastname']); // Doe
$job->arg('interface', $_GET['interface']); // eth0

$job->must('echo " "'); // stops here if shell errors
$job->may('ip addr show dev |grep inet |awk \'{print $2}\''); // will not stop here if shell errors
$job->may('ifconfig |grep inet |awk \'{print $2}\''); // will not stop here if shell errors
$job->must('/sbin/someCustomScript ');

$ok = $job->run(); // run commands in order

echo "Output: " . json_encode($job->output());
echo "Errors: " . json_encode($job->errors());

echo $ok ? "Run successful" : "Run failed";
```

### Output

```
> Output: ["John Doe", null, "192.168.10.16", "Hello, John Doe!"]
> Errors: [null, "sh: command not found: ip", null, null]
> Run successful
```