From 9063f08797dc1be95f493d23f2947d7dfbd0e1da Mon Sep 17 00:00:00 2001 From: RedYetiDev <38299977+RedYetiDev@users.noreply.github.com> Date: Thu, 25 Apr 2024 08:49:26 -0400 Subject: [PATCH 1/3] child_process: throw exception for batch w/o shell --- lib/internal/child_process.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/internal/child_process.js b/lib/internal/child_process.js index 49edaba5b558e9..b6d6cd4ba24573 100644 --- a/lib/internal/child_process.js +++ b/lib/internal/child_process.js @@ -11,6 +11,7 @@ const { ObjectSetPrototypeOf, ReflectApply, StringPrototypeSlice, + StringPrototypeToLowerCase, Symbol, SymbolDispose, Uint8Array, @@ -61,6 +62,7 @@ const { isArrayBufferView } = require('internal/util/types'); const spawn_sync = internalBinding('spawn_sync'); const { kStateSymbol } = require('internal/dgram'); const dc = require('diagnostics_channel'); +const { extname } = require('path'); const childProcessChannel = dc.channel('child_process'); const { @@ -418,7 +420,12 @@ ChildProcess.prototype.spawn = function(options) { this._handle.close(); this._handle = null; - throw new ErrnoException(err, 'spawn'); + const exception = new ErrnoException(err, 'spawn'); + const ext = StringPrototypeToLowerCase(extname(options.file)); + if (ext === '.cmd' || ext === '.bat') { + exception.message = '"shell" must be "true" when spawning ' + + 'a batch executable'; + } } else { process.nextTick(onSpawnNT, this); } From a888af98fd4034a8774a0db08c13de896a71bd79 Mon Sep 17 00:00:00 2001 From: Aviv Keller <38299977+RedYetiDev@users.noreply.github.com> Date: Sat, 27 Apr 2024 11:12:15 -0400 Subject: [PATCH 2/3] child_process: throw the exception --- lib/internal/child_process.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/internal/child_process.js b/lib/internal/child_process.js index b6d6cd4ba24573..eb22b1e4dc51e1 100644 --- a/lib/internal/child_process.js +++ b/lib/internal/child_process.js @@ -426,6 +426,7 @@ ChildProcess.prototype.spawn = function(options) { exception.message = '"shell" must be "true" when spawning ' + 'a batch executable'; } + throw exception; } else { process.nextTick(onSpawnNT, this); } From ae573d4d34822ff1b2e27b4090fc156cfa7739c2 Mon Sep 17 00:00:00 2001 From: Aviv Keller <38299977+RedYetiDev@users.noreply.github.com> Date: Sun, 18 Aug 2024 19:42:28 -0400 Subject: [PATCH 3/3] [windows test] --- test/parallel/test-child-process-spawn-windows-batch-file.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/parallel/test-child-process-spawn-windows-batch-file.js b/test/parallel/test-child-process-spawn-windows-batch-file.js index 242f2d2d1bb468..71c21ac6cc4f83 100644 --- a/test/parallel/test-child-process-spawn-windows-batch-file.js +++ b/test/parallel/test-child-process-spawn-windows-batch-file.js @@ -57,6 +57,7 @@ function testSpawn(filename, code) { } if (!e) throw new Error(`Exception expected for ${filename}`); assert.strictEqual(e.code, code); + assert.match(e.message, /"shell" must be "true"/); } else { return new Promise((resolve) => { cp.spawn(filename).once('error', common.mustCall(function(e) {