Running a command in a Grunt Task
Alternatively you could load in grunt plugins to help this:
grunt-shell example:
shell: { make_directory: { command: 'mkdir test' }}
or grunt-exec example:
exec: { remove_logs: { command: 'rm -f *.log' }, list_files: { command: 'ls -l **', stdout: true }, echo_grunt_version: { command: function(grunt) { return 'echo ' + grunt.version; }, stdout: true }}
Check out grunt.util.spawn
:
grunt.util.spawn({ cmd: 'rm', args: ['-rf', '/tmp'],}, function done() { grunt.log.ok('/tmp deleted');});
I've found a solution so I'd like to share with you.
I'm using grunt under node so, to call terminal commands you need to require 'child_process' module.
For example,
var myTerminal = require("child_process").exec, commandToBeExecuted = "sh myCommand.sh";myTerminal(commandToBeExecuted, function(error, stdout, stderr) { if (!error) { //do something }});