UPDATE: All of the fixes contained in this fork have been merged upstream and included in version 0.3.1 of grunt-shell-spawn. If you were previously using this fork in your projects, you should now be able to use grunt-shell-spawn directly (as long as you're using version 0.3.1 or later).
A fork on grunt-shell-spawn with the following fixes:
- Don't convert forward slashes to backslashes on Windows (#12).
- Fix the broken
:kill
task to actually kill the process instead of orphaning it (#14), and add support for:kill
on Windows.- Caveat: it is now required to explicitly use
:kill
to clean up any background processes you started, as they will otherwise continue running after grunt finishes.
- Caveat: it is now required to explicitly use
- Fix for capturing
stderr
(#15).
This plugin requires grunt >= 0.4.x. For grunt 0.3.x, use version 0.1.3
.
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');
Let's take for example launching a compass watch
in background:
shell: {
command: 'compass watch',
options: {
async: true
}
}
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
}
}
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();
}
}
},
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.
MIT License (c) Sindre Sorhus