PHPackages                             fuhry/system-shell - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. fuhry/system-shell

ActiveLibrary

fuhry/system-shell
==================

Library for executing programs from PHP, as safely as possible.

03.2kPHPCI failing

Since Sep 9Pushed 6y agoCompare

[ Source](https://github.com/fuhry/system-shell)[ Packagist](https://packagist.org/packages/fuhry/system-shell)[ RSS](/packages/fuhry-system-shell/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

system-shell
============

[](#system-shell)

OO interface to command execution in PHP. Encourages safer argument handling. This is a clean-room, copyright-encumberment-free reimplementation of functionality I implemented in several projects with my employer.

Features
--------

[](#features)

### `execf()`/`vexecf()`: printf-style formatted commands

[](#execfvexecf-printf-style-formatted-commands)

The original reason I wrote this class was to encourage myself and fellow engineers to obsessively escape any and all command line arguments consisting of any sort of data - even semi-trusted data from elsewhere in the application.

To achieve this goal, the `execf()` method takes three arguments:

- `$command`: The base command to execute, i.e. the executable to run. Example: `ls`
- `$argTemplate`: printf-style template string for arguments. You can include switches in here, but should not include any user data. Placeholders for user data should not be quoted. Example: `-la %s`.
- `...$args`: Arguments that will be passed to `sprintf()`. User data in here should not be quoted; all arguments will be cast to strings and quoted appropriately for the command line.

### PATH resolution

[](#path-resolution)

The `Shell` class uses an `IResolver` (defaulting to `PathEnvironmentResolver`) to calculate the full path of the executable before it's run. If the system's `PATH` is empty, a reasonable default is used.

### Logging

[](#logging)

The `Shell` class implements PSR-3 `LoggerAwareInterface`, so you can supply any logger you want to log command execution and results.

### Separate stdout/stderr capture

[](#separate-stdoutstderr-capture)

The `ExecuteResult` instance returned from all commands has three methods:

- `getExitStatus`: Returns the process's integer exit status
- `getStandardOutput`: Returns the process's standard output as a string
- `getStandardError`: Returns the process's standard error as a string

### Automatic exceptions

[](#automatic-exceptions)

You can instruct `Shell` to automatically throw exceptions when commands fail:

```
$shell->throwsExceptionOnErrorExit(true)->execf('false'); // throws ShellException
```

TODO
====

[](#todo)

- Add support for decorators (sudo, timeout, others?)
- Add ability to control logging behavior - enable/disable profiling, logging of arguments, etc.
- Add support for supplying standard input

License
=======

[](#license)

```
THE MIT LICENSE

Copyright (c) 2017 Dan Fuhry

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1379912?v=4)[Dan Fuhry](/maintainers/fuhry)[@fuhry](https://github.com/fuhry)

---

Top Contributors

[![fuhry](https://avatars.githubusercontent.com/u/1379912?v=4)](https://github.com/fuhry "fuhry (1 commits)")

### Embed Badge

![Health badge](/badges/fuhry-system-shell/health.svg)

```
[![Health](https://phpackages.com/badges/fuhry-system-shell/health.svg)](https://phpackages.com/packages/fuhry-system-shell)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
