Reputation: 60895
I'm running require('child_process').exec('npm install')
as a child process in a node.js script, but I want it to retain console colors. I'm running in windows, but want this script to be portable (e.g. to linux). How do I start a process that think's it's being run from the console?
Note: I'd rather not have npm-specific answers, but an answer that allows me to trick any command.
Upvotes: 1
Views: 1320
Reputation: 91679
You can do this by letting the child process inherit the master process' stdio
streams. This means you need to user spawn
rather than exec
, and this what you'd do:
var spawn = require('child_process').spawn;
var child = spawn('npm', ['install'], {
stdio: 'inherit'
});
Upvotes: 3