From b780495ee1756dd03995050d8d8c7c1bbeee4a6c Mon Sep 17 00:00:00 2001 From: Ofri Peretz Date: Mon, 23 Nov 2026 11:56:11 -0500 Subject: [PATCH 1/2] fix: ignore EPIPE on stdin when the process exits early --- src/main.ts | 8 ++++++++ src/test/main_test.ts | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/src/main.ts b/src/main.ts index aa9dc0c..e165d38 100644 --- a/src/main.ts +++ b/src/main.ts @@ -350,6 +350,14 @@ export class ExecProcess implements Result { if (handle.stdin) { const {stdin} = options; + // A child may exit without reading all of its input (e.g. `head`), + // which surfaces as EPIPE here. That is not a failure of ours. + handle.stdin.on('error', (err: NodeJS.ErrnoException) => { + if (err.code !== 'EPIPE') { + this._thrownError = err; + } + }); + if (typeof stdin === 'string') { handle.stdin.end(stdin); } else { diff --git a/src/test/main_test.ts b/src/test/main_test.ts index a852620..7b48f5d 100644 --- a/src/test/main_test.ts +++ b/src/test/main_test.ts @@ -194,6 +194,15 @@ describe('exec (async)', () => { expect(result.exitCode).toBe(0); }); + test('does not crash when the process exits without reading stdin', async () => { + // Larger than the pipe buffer, so the write is still pending on exit + const result = await x('node', ['-e', 'process.exit(0)'], { + stdin: 'x'.repeat(4 * 1024 * 1024) + }); + + expect(result.exitCode).toBe(0); + }); + test('supports stdin passed as another process (Result)', async () => { const proc = x('node', ['-e', "process.stdout.write('foo\\nbar')"]); const result = await x( From 48f2edc498eb988b9b4dfaeb9db862a3b14e8ba4 Mon Sep 17 00:00:00 2001 From: James Garbutt <43081j@users.noreply.github.com> Date: Tue, 24 Nov 2026 18:53:56 +0000 Subject: [PATCH 2/2] chore: add windows support --- src/main.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main.ts b/src/main.ts index e165d38..89839bc 100644 --- a/src/main.ts +++ b/src/main.ts @@ -351,9 +351,10 @@ export class ExecProcess implements Result { const {stdin} = options; // A child may exit without reading all of its input (e.g. `head`), - // which surfaces as EPIPE here. That is not a failure of ours. + // which surfaces as EPIPE here (EOF on Windows). That is not a failure + // of ours. handle.stdin.on('error', (err: NodeJS.ErrnoException) => { - if (err.code !== 'EPIPE') { + if (err.code !== 'EPIPE' && err.code !== 'EOF') { this._thrownError = err; } });