Created
May 25, 2015 15:10
-
-
Save mathieucarbou/157e90962c37c741dd02 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = spawn | |
var _spawn = require("child_process").spawn | |
var EventEmitter = require("events").EventEmitter | |
var cygwin = process.platform === "win32" && (process.env.ORIGINAL_PATH || '').indexOf('/cygdrive/') != -1; | |
function spawn (cmd, args, options) { | |
if(cygwin && cmd.indexOf('cmd.exe') != -1) { | |
cmd = 'c:\\cygwin\\bin\\bash.exe'; | |
args[0] = '-c'; | |
console.log('spawn', cmd, args); | |
} | |
var raw = _spawn(cmd, args, options) | |
var cooked = new EventEmitter() | |
raw.on("error", function (er) { | |
er.file = cmd | |
cooked.emit("error", er) | |
}).on("close", function (code, signal) { | |
// Create ENOENT error because Node.js v0.8 will not emit | |
// an `error` event if the command could not be found. | |
if (code === 127) { | |
var er = new Error('spawn ENOENT') | |
er.code = 'ENOENT' | |
er.errno = 'ENOENT' | |
er.syscall = 'spawn' | |
er.file = cmd | |
cooked.emit('error', er) | |
} else { | |
cooked.emit("close", code, signal) | |
} | |
}) | |
cooked.stdin = raw.stdin | |
cooked.stdout = raw.stdout | |
cooked.stderr = raw.stderr | |
cooked.kill = function (sig) { return raw.kill(sig) } | |
return cooked | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment