preserve color when executing child_process.spawn

Solution 1:

There are new 'stdio' option for child_process.spawn(). Try following:

spawn("path to executable", ["params"], {stdio: "inherit"});

"Inherit" means [0, 1, 2] or [process.stdin, process.stdout, process.stderr].

Solution 2:

crossplatform solution that worked for me was to use both shell: true and stdio: 'inherit':

const spawn = require('child_process').spawn;

spawn('node', ['./child.js'], { shell: true, stdio: 'inherit' });

thanks @59naga https://github.com/nodejs/node/issues/2333