# grunt-shell-spawn

> Grunt task to run shell commands

Latest version **0.5.0** (published 2025-04-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install grunt-shell-spawn
pnpm add grunt-shell-spawn
yarn add grunt-shell-spawn
bun add grunt-shell-spawn
```

Provides the command `grunt-shell-spawn`.

## Health

**Score 25/100 (F)** — status: maintenance-mode.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.0 |
| Published | 2025-04-01 |
| First published | 2013-04-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=16 |
| Dependencies | 1 |
| Unpacked size | 23.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 62 |
| Author | Sindre Sorhus |
| Maintainers | cri5ti, dandv, bittorture, jeking3 |
| Keywords | gruntplugin, grunt, shell, command, exec, spawn, cli |

## Links

- npm: https://www.npmjs.com/package/grunt-shell-spawn
- Repository: https://github.com/jeking3/grunt-shell-spawn
- Issues: https://github.com/jeking3/grunt-shell-spawn/issues
- npm.io page: https://npm.io/package/grunt-shell-spawn

## Dependencies (1)

- [grunt](https://npm.io/package/grunt.md) ^1.6.1

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 0.5.0 (latest) — 2025-04-01
- 0.4.0 — 2019-01-30
- 0.3.12 — 2019-01-26
- 0.3.11 — 2019-01-26
- 0.3.10 — 2015-10-02
- 0.3.9 — 2015-09-08
- 0.3.8 — 2015-05-01
- 0.3.7 — 2015-05-01
- 0.3.6 — 2015-04-30
- 0.3.4 — 2015-04-30
- 0.3.3 — 2015-04-30
- 0.3.2 — 2015-03-25
- 0.3.1 — 2015-01-08
- 0.3.0 — 2013-10-01
- 0.2.4 — 2013-05-02
- … 5 more at https://npm.io/package/grunt-shell-spawn/versions

## README

# grunt-shell-spawn [![Build Status](https://travis-ci.org/jeking3/grunt-shell-spawn.svg?branch=master)](https://travis-ci.org/jeking3/grunt-shell-spawn) [![Build status](https://ci.appveyor.com/api/projects/status/vpf0vqtixd99suii/branch/master?svg=true)](https://ci.appveyor.com/project/jeking3/grunt-shell-spawn/branch/master)

> A fork of [sindresorhus][1]'s [grunt-shell][2] ***with support for background processes***.
> 
> *(e.g.: start a `compass watch` in the background)*

This plugin lets you:

- Run processes synchronously or asynchronously.
- Process stdout and stderr using functions.
- Run a function when an asynchronous process ends that gets the exit code.
- Kill an asynchronous process.
 
### Requirements

- node.js 16.x or later
- grunt 1.6 or later

### Install

    npm install grunt-shell-spawn --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with:

    grunt.loadNpmTasks('grunt-shell-spawn');

### Examples

#### Simple task:

Let's take for example launching a `compass watch` in background:

```javascript
shell: {
    command: 'compass watch',
    options: {
        async: true
    }
}
```

#### Multitask:

```javascript
shell: {
    compassWatch: {
        command: 'compass watch',
        options: {
            async: true,
            execOptions: {
                cwd: './src/www/'
           }
       }
    },
    coffeeCompile: {
        command: 'coffee -b -c -o /out /src',
        options: {
            async: false,
            execOptions: {
                cwd: './src/www/'
            }
        }
    },
    options: {
        stdout: true,
        stderr: true,
        failOnError: true
    }
}
```

#### Custom callbacks:

Works in synchronous or asynchronous mode.

```
    asyncWithCallbacks: {
        command: 'sleep 3 & echo HELLO & sleep 1 & echo WORLD & sleep 2',
        options: {
            async: true,
            stdout: function(data) { /* ... */ },
            stderr: function(data) { /* ... */ },
            callback: function(exitCode, stdOutStr, stdErrStr, done) { 
                done();
            }
        }
    }, 
```

#### Killing an async process

Stop a running async task with the `:kill` task argument. 

```
    server: {
        command: 'redis-server',
        options: {
            async: true,
        }
    },
```

> `grunt shell:server shell:somethingElse shell:server:kill`

The process will be killed with a SIGKILL.

Please note that processes that are not killed will continue running even after grunt finishes, unless explicitly terminated using `:kill`. This means it is required to use `:kill` to clean up any processes you started, unless you want them to continue running in the background.

## Release History

 * 2025-03-29   v0.5.0   Updated dependencies (grunt 1.6+, node 16+)
 * 2019-05-26   v0.4.1   Updated dependencies
 * 2019-01-29   v0.4.0   Added CI on Travis, AppVeyor; updated node.js engine dependency to >=4
 * 2019-01-26   v0.3.12  Removed dependency on exec-sync to resolve security advisory
 * 2015-01-07   v0.3.1   Fix the :kill task on UNIX and Windows
 * 2013-04-06   v0.1.3   Last version with support for grunt 0.3.x

## License

MIT License
(c) [Sindre Sorhus](http://sindresorhus.com)


[1]: https://github.com/sindresorhus
[2]: https://github.com/sindresorhus/grunt-shell

[cp_spawn]: http://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options

---
_Source: https://npm.io/package/grunt-shell-spawn · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
