use spawn instead of exec
Closed this issue · 1 comments
technote-space commented
コマンドが完了するまでログが表示されないため
technote-space commented
function execCommand(cmd: string): Promise<string> {
return new Promise((resolve, reject) => {
const process = spawn(cmd, [], { shell: true })
let stdout = ""
process.stdout.on('data', (data) => {
console.log(data.toString());
stdout += data.toString();
});
process.stderr.on('data', (data) => {
console.error(data.toString());
});
process.on('exit', (code) => {
if (code !== 0) {
reject(new Error(code ? code.toString() : undefined))
}
resolve(stdout)
});
});
}