Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

child_process: throw different error message for executing batch files w/o shell: true #52685

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/internal/child_process.js
Expand Up @@ -11,6 +11,7 @@ const {
ObjectSetPrototypeOf,
ReflectApply,
StringPrototypeSlice,
StringPrototypeToLowerCase,
Symbol,
SymbolDispose,
Uint8Array,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -418,7 +420,13 @@ 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';
}
throw exception;
} else {
process.nextTick(onSpawnNT, this);
}
Expand Down