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.
- Host: GitHub
- URL: https://github.com/crit/php-exec-jobs
- Owner: crit
- License: mit
- Created: 2019-05-30T22:36:00.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-06-03T23:21:19.000Z (about 7 years ago)
- Last Synced: 2024-04-30T14:02:09.658Z (about 2 years ago)
- Topics: php, shell
- Language: PHP
- Size: 8.79 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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
```