Skip to content

Commit

Permalink
inherit stdio
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed May 17, 2024
1 parent 3da11c4 commit 464591c
Showing 1 changed file with 2 additions and 20 deletions.
22 changes: 2 additions & 20 deletions build/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,10 @@ import {spawn} from 'child_process';

export function execute(cmd, args, options) {
return new Promise((resolve, reject) => {
const proc = spawn(cmd, args, {...options || {}, shell: true});
let stdout = [];
let stderr = [];

proc.stdout.setEncoding('utf8');
proc.stdout.on('data', function(data) {
const str = data.toString();
const lines = str.split(/(\r?\n)/g);
stdout = stdout.concat(lines);
});

proc.stderr.setEncoding('utf8');
proc.stderr.on('data', function(data) {
const str = data.toString();
const lines = str.split(/(\r?\n)/g);
stderr = stderr.concat(lines);
});

const proc = spawn(cmd, args, {...options || {}, shell: true, stdio: 'inherit'});
proc.on('close', function(code) {
const result = {exitCode: code, stdout: stdout.join('\n'), stderr: stderr.join('\n')};
const result = {exitCode: code};
if (parseInt(code) !== 0) {
console.error(result.stderr.replaceAll(/\n\n+/g, '\n'));
reject(result);
} else {
resolve(null, result);
Expand Down

0 comments on commit 464591c

Please sign in to comment.