Socket
Book a DemoInstallSign in
Socket

grunt-shell-spawn

Package Overview
Dependencies
Maintainers
4
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-shell-spawn

Grunt task to run shell commands

0.5.0
latest
Source
npmnpm
Version published
Weekly downloads
7.8K
-0.14%
Maintainers
4
Weekly downloads
 
Created
Source

grunt-shell-spawn Build Status Build status

A fork of sindresorhus's grunt-shell 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:

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

Multitask:

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

Keywords

gruntplugin

FAQs

Package last updated on 01 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.