PHPackages                             command-runner/command-runner - 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. [CLI &amp; Console](/categories/cli)
4. /
5. command-runner/command-runner

ActiveLibrary[CLI &amp; Console](/categories/cli)

command-runner/command-runner
=============================

Execute console command and process result.

025PHP

Since Aug 23Pushed 9y ago1 watchersCompare

[ Source](https://github.com/AlexyAV/command-runner)[ Packagist](https://packagist.org/packages/command-runner/command-runner)[ RSS](/packages/command-runner-command-runner/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (1)Used By (0)

[![Build Status](https://camo.githubusercontent.com/a449e37aa06037a81c2780c3c95b9ed4ed2ac1b60f6bfb92325593979c98a1ea/68747470733a2f2f7472617669732d63692e6f72672f416c65787941562f636f6d6d616e642d72756e6e65722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/AlexyAV/command-runner)[![Test Coverage](https://camo.githubusercontent.com/e2aded1a0ff5e18b36841a871aefacaf1b54f230842872df2ab7e1ea5d705f37/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f416c65787941562f636f6d6d616e642d72756e6e65722f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/AlexyAV/command-runner/coverage)

Command runner
==============

[](#command-runner)

Execute console command and process result.

This library allows you to launch an external application via the console and process the results. Also can be use to safely run daemons.

\##Installation

Add to your composer.json

```
"command-runner/command-runner": "dev-master"

```

Example of single command:

```
$commandRunner = new CommandRunner;
$result = $commandRunner->setCommand('pwd')->execute();

//  [
//      'output'     => 'path_to_your_working_dir',
//      'resultCode' => 0
//  ]
```

With additionals arguments:

```
...
$result = $commandRunner->setCommand('ls -la')
                        ->setArgument(['./assets'])
                        ->execute();

//  [
//      'output'     => [
//          'drwxrwxr-x 1 vagrant vagrant  4096 Aug 22 13:32 e45d6ac2',
//          'drwxrwxr-x 1 vagrant vagrant  4096 May 12 17:51 efd003fa',
//          ...
//      ],
//      'resultCode' => 0
//  ]
```

Arguments are optional. You can path command with all arguments to `setCommand` method.

If you want to get raw command output:

```
...
$commandRunner->setRawOutput(true); // false by default

//  [
//      'output'     =>
//          'drwxrwxr-x 1 vagrant vagrant  4096 Aug 22 13:32 e45d6ac2
//          drwxrwxr-x 1 vagrant vagrant  4096 May 12 17:51 efd003fa
//          ...
//      ,
//      'resultCode' => 0
//  ]
```

Accordingly to redirect standard command output use `setWaitForOutput(false)`.

Command queue
-------------

[](#command-queue)

Class `CommandQueue` can be used to perform multiple commands with the possibility of setting the individual parameters:

```
$commandQueue = new CommandQueue();
$commandQueue->setCommandQueue(
    [
        // first command
        [
            'command'   => 'ps aux | grep',
            'escape'    => false,           // false by default
            'arguments' => ['rabbitmq'],    // optional
            'options'   => [
                'saveOutputName' => 'ps_output_file_name'
            ],
        ],
        // second command
        [
            'command' => 'ls -la',
            'escape'  => false,
            'options' => [
                'saveOutputName' => 'ls_output_file_name'
            ],
        ],
         // call daemon
        [
            'command' => './start_daemon',
            'escape'  => false,
            'options' => [
                'waitForOutput' => false
            ],
        ]
    ]
);

$result = $commandQueue->execute();

// Source array will be modified with command results:
// [
//     'command'     => 'ls -la',
//     'escape'      => false,
//     'options'     => [
//         'saveOutputName' => 'ls_output_file_name'
//     ],
//     'output'      => [
//           ...
//           'drwxrwxr-x 1 vagrant vagrant  4096 Aug 22 13:30 fonts',
//           'drwxrwxr-x 1 vagrant vagrant  4096 Aug 22 13:30 img'
//           ...
//     'resultCode' => 0
// ]
```

Save output
-----------

[](#save-output)

Every command result can be saved to file. By default all files saves to `/tmp/commandRunnerOutput`. Create new instance of `CommandOutput` class to change default behavior:

```
...
$commandOutput = new CommandOutput;
$commandOutput->setOutputPath(__DIR__);

$commandRunner->setCommandOutput($commandOutput)
              ->setSaveOutputName('resultFileName.txt');
...
// File with command result will be saved to working dir.
```

You can implement `OutputInterface` for you custom output handler.

In case of command queue output handler can be specified with:

```
...
$commandOutput = new CommandOutput;
$commandOutput->setOutputPath(__DIR__);

$commandQueue->setCommandQueue(
    [
        [
            'command'   => 'ps aux | grep',
            'escape'    => false,           // false by default
            'arguments' => ['rabbitmq'],    // optional
            'options'   => [
                'saveOutputName'   => 'ps_output_file_name',
                'setCommandOutput' => $commandOutput
            ],
        ],
    ]
);
...
```

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

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://www.gravatar.com/avatar/359f6a15cf5e394411373f6593f62dcbf0d21aea441350b6afaa8fd5afedd94d?d=identicon)[avpretty](/maintainers/avpretty)

---

Top Contributors

[![AlexyAV](https://avatars.githubusercontent.com/u/5259115?v=4)](https://github.com/AlexyAV "AlexyAV (16 commits)")

### Embed Badge

![Health badge](/badges/command-runner-command-runner/health.svg)

```
[![Health](https://phpackages.com/badges/command-runner-command-runner/health.svg)](https://phpackages.com/packages/command-runner-command-runner)
```

###  Alternatives

[seld/cli-prompt

Allows you to prompt for user input on the command line, and optionally hide the characters they type

24726.4M22](/packages/seld-cli-prompt)[illuminate/console

The Illuminate Console package.

13045.3M6.2k](/packages/illuminate-console)[styleci/cli

The CLI tool for StyleCI

71464.1k9](/packages/styleci-cli)[winbox/args

Windows command-line formatter

20718.9k21](/packages/winbox-args)

PHPackages © 2026

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