Execute OS specific script in node / Grunt Execute OS specific script in node / Grunt shell shell

Execute OS specific script in node / Grunt


You could take advantage of node's process.platform:

process.platform
What platform you're running on: 'darwin', 'freebsd', 'linux', 'sunos' or 'win32'

console.log('This platform is ' + process.platform);

Then within the code, optionally add the file extensions based on that:

if (process.platform === "win32") {    ext = ".cmd";} else {    ext = ".sh";}


Using grunt-shell or any other shell command tool, take advantage of the similarities between win and *nix shells, particularly ||. The first cmd will fail on *nix and fallback to sh:

    shell: {        options: {            stderr: false,            failOnError: true        },        command: 'cmd command.cmd || sh command.sh'    }