Files
coins/bin/async-spawn.ts
T

22 lines
529 B
TypeScript

import process from 'process';
import { spawn } from 'child_process';
export const asyncSpawn = (command: string, args: string[]) => {
return new Promise((resolve, reject) => {
const child = spawn(command, args, {
stdio: 'inherit'
});
child.on('error', reject);
child.stdout?.on('data', process.stdout.write);
child.stderr?.on('data', process.stderr.write);
child.on('close', code => {
if (code === 0) {
resolve(code);
} else {
reject(code);
}
});
});
};