Fix ERR_STREAM_WRITE_AFTER_END
This commit is contained in:
parent
00d37a9871
commit
70e656229c
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -33,10 +33,12 @@ export function isNumeric(str: string): boolean {
|
||||||
|
|
||||||
export async function runCmd(cmd: string, args: string[], workingDir: string, logStreamOrFile: string | WriteStream, silent: boolean = false): Promise<void> {
|
export async function runCmd(cmd: string, args: string[], workingDir: string, logStreamOrFile: string | WriteStream, silent: boolean = false): Promise<void> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const runningProcess = spawnProcess(cmd, args, {shell: true, cwd: workingDir, env: process.env});
|
const closeLogStream = typeof logStreamOrFile == 'string';
|
||||||
const logStream = typeof logStreamOrFile != 'string' ? logStreamOrFile :
|
const logStream = typeof logStreamOrFile != 'string' ? logStreamOrFile :
|
||||||
createWriteStream(logStreamOrFile, {encoding: 'utf-8', flags: 'a' /* append */});
|
createWriteStream(logStreamOrFile, {encoding: 'utf-8', flags: 'a' /* append */});
|
||||||
|
|
||||||
|
const runningProcess = spawnProcess(cmd, args, {shell: true, cwd: workingDir, env: process.env});
|
||||||
|
|
||||||
runningProcess.stdout.on('data', (data) => {
|
runningProcess.stdout.on('data', (data) => {
|
||||||
logStream.write(data);
|
logStream.write(data);
|
||||||
|
|
||||||
|
@ -53,7 +55,9 @@ export async function runCmd(cmd: string, args: string[], workingDir: string, lo
|
||||||
});
|
});
|
||||||
|
|
||||||
runningProcess.on('close', (code) => {
|
runningProcess.on('close', (code) => {
|
||||||
logStream.close();
|
if (closeLogStream) {
|
||||||
|
logStream.close();
|
||||||
|
}
|
||||||
|
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
return reject({err: new Error(`process exited with code ${code}`), cmd, workingDir});
|
return reject({err: new Error(`process exited with code ${code}`), cmd, workingDir});
|
||||||
|
|
Loading…
Reference in New Issue