From 52b36ef6e03abee51f0032728443c5a4661e37bc Mon Sep 17 00:00:00 2001 From: Justin Grote Date: Sat, 25 Sep 2021 09:14:28 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20PSProcess=20stderr=20handler=20w?= =?UTF-8?q?as=20being=20registered=20more=20than=20once?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/powershell.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/powershell.ts b/src/powershell.ts index f8e6f5be..2db72ba0 100644 --- a/src/powershell.ts +++ b/src/powershell.ts @@ -174,6 +174,16 @@ export class PowerShell { '-Command', '-' ]) + // Warn if we have more than one listener set on a process + this.psProcess.stdout.setMaxListeners(2) + this.psProcess.stderr.setMaxListeners(1) + // TODO: More robust stderr handling + this.psProcess.stderr.once('data', (data: Buffer) => { + throw new Error( + `Error Received on stderr from pwsh: ` + data.toString() + ) + }) + if (!this.psProcess.pid) { throw new Error(`Failed to start PowerShell process.`) } @@ -204,11 +214,6 @@ export class PowerShell { createSplitPSOutputStream(psOutput) ]) - // TODO: More robust stderr handling - this.psProcess.stderr.once('data', (data: Buffer) => { - throw new Error(`Error Received on stderr from pwsh: ` + data.toString()) - }) - const runnerScriptPath = resolve( __dirname, '..',