node-cross-spawn icon indicating copy to clipboard operation
node-cross-spawn copied to clipboard

Use the `/q` flag with `cmd.exe`

Open zenflow opened this issue 4 years ago • 0 comments

Is this an nodejs issue we can solve here in userland?

https://github.com/nodejs/node/issues/27120 - Use the /q flag with cmd.exe in child_process.spawn()

I think it makes sense to add the flag by default here (in cross-spawn), without any option, even if it won't be done by default in Node.js child_process because it prevents a "special" Windows behavior (i.e. printing an extra line like D:\foo\bar>echo hello to the console as the initial output https://github.com/nodejs/node/issues/27120#issuecomment-481033509).

Node.js core needs to make it optional since some user some time might want to use this Windows-only behavior, but cross-spawn doesn't have that burden.

Execa simply prepends the /q flag to the parsed args like this:

https://github.com/sindresorhus/execa/blob/717d29d539e0bdf1666c1a4bc10fa406d996e7b3/index.js#L28-L56

	const parsed = crossSpawn._parse(file, args, options);
	file = parsed.command;
	args = parsed.args;
	options = parsed.options;
        // ... mutations to `options` ...
	if (process.platform === 'win32' && path.basename(file, '.exe') === 'cmd') {
		// #116
		args.unshift('/q');
	}
        // ... calls Node.js `child_process.spawn` with file, args, options ...

Referenced issue: https://github.com/sindresorhus/execa/issues/116

zenflow avatar Jul 06 '20 11:07 zenflow