| 135 | |
| 136 | // Wrapper around exec() to enable echoing output to console in real time |
| 137 | function execAsync(cmd, opts, pipe, callback) { |
| 138 | opts = common.extend({ |
| 139 | silent: common.config.silent, |
| 140 | fatal: common.config.fatal, // TODO(nfischer): this and the line above are probably unnecessary |
| 141 | cwd: _pwd().toString(), |
| 142 | env: process.env, |
| 143 | maxBuffer: DEFAULT_MAXBUFFER_SIZE, |
| 144 | encoding: 'utf8', |
| 145 | }, opts); |
| 146 | |
| 147 | var c = child.exec(cmd, opts, function (err, stdout, stderr) { |
| 148 | if (callback) { |
| 149 | if (!err) { |
| 150 | callback(0, stdout, stderr); |
| 151 | } else if (err.code === undefined) { |
| 152 | // See issue #536 |
| 153 | /* istanbul ignore next */ |
| 154 | callback(1, stdout, stderr); |
| 155 | } else { |
| 156 | callback(err.code, stdout, stderr); |
| 157 | } |
| 158 | } |
| 159 | }); |
| 160 | |
| 161 | if (pipe) c.stdin.end(pipe); |
| 162 | |
| 163 | if (!opts.silent) { |
| 164 | c.stdout.pipe(process.stdout); |
| 165 | c.stderr.pipe(process.stderr); |
| 166 | } |
| 167 | |
| 168 | return c; |
| 169 | } |
| 170 | |
| 171 | //@ |
| 172 | //@ ### exec(command [, options] [, callback]) |