The api child process can be used to execute a shell script in node.js.
I am using child_process.exec (command [, options], callback) function
as an option, the user user can set the shell: '/ path / to / shell' to select the shell to be used. (The default is "/ bin / sh")
The settings for {shell: '/ bin / bash'} do not make exec runt a command with bash.
I checked this by issuing the command "echo $ 0" which prints "/ bin / sh".
How to use bash with child_process.exec through shell?
(My goal is to use path definitions in bashrc, now when I try to use grunt, the binary cannot be found. Installing cwd, the current working directory in the parameter dictionary works as expected)
----------------- UPDATE example
'use strict'; var cp = require('child_process'); cp.exec('echo $0', { shell: '/bin/bash' }, function(err, stdout, stderr){ if(err){ console.log(err); console.log(stderr); } console.log(stdout); });
Output:
/bin/sh
which bash
prints: / ben / bash
source share