| 1 |
'use strict' |
| 2 |
|
| 3 |
const cp = require('child_process') |
| 4 |
|
| 5 |
function spawn (exe, args, opts) { |
| 6 |
return new Promise((resolve, reject) => { |
| 7 |
const proc = cp.spawn(exe, args, opts) |
| 8 |
const stdout = [] |
| 9 |
const stderr = [] |
| 10 |
|
| 11 |
proc.stdout.on('data', buf => stdout.push(buf)) |
| 12 |
proc.stderr.on('data', buf => stderr.push(buf)) |
| 13 |
|
| 14 |
proc.on('error', reject) |
| 15 |
proc.on('close', status => { |
| 16 |
resolve({ |
| 17 |
status, |
| 18 |
stdout: Buffer.concat(stdout).toString(), |
| 19 |
stderr: Buffer.concat(stderr).toString() |
| 20 |
}) |
| 21 |
}) |
| 22 |
}) |
| 23 |
} |
| 24 |
|
| 25 |
module.exports = spawn |