mde/jake — Issue #79: best way to execute shell commands and preserve color
Author: prabirshrestha
Created: 2011-10-15 08:17:14+00:00
State: open

I want to execute a shell command in windows using cmd.

var spawn = require('child_process').spawn,
cmd = spawn('cmd', ['/s', '/c', 'C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\MSBuild c:\\test.sln']);

cmd.stdout.on('data', function(data){
process.stdout.write(data);
});

cmd.stderr.on('data', function(data){
process.stderr.write(data);
});

cmd.on('exit', function(code){
console.log(code);
});

The problem is the color is not preserved. Rather it uses default color.

Any idea how to redirect the stdout and preserve the color.

Here is the original question I posted in stackoverflow. http://stackoverflow.com/questions/7725809/preserve-color-when-executing-child-process-spawn