Closed
Description
Version
v18.3.0
Platform
Linux *** 5.13.0-44-generic #49~20.04.1-Ubuntu SMP *** x86_64 x86_64 x86_64 GNU/Linux
Subsystem
node:child_process
What steps will reproduce the bug?
- Create an ESM file with the following content:
import { execFile, execFileSync } from "node:child_process"; const stdout = execFileSync( "echo", ["foo", "bar"], { shell: "/bin/bash" }, ); console.log(`execFileSync: ${stdout}`); // Outputs: "execFileSync: \n" execFile( "echo", ["foo", "bar"], { shell: "/bin/bash" }, (_, stdout) => { console.log(`execFile: ${stdout}`); // Output: "execFile: foo bar\n" }, );
- Note that the
options
object includes a non-falsy value for theshell
option. (for reference, see thechild_process.execFile
documentation). - Run the file using the following command to be able to view the
args
argument toexecFile(Sync)
after normalization:$ env NODE_DEBUG=child_process node t.js 2>&1 | grep -w args
- Observe the different behaviour:
args: [ '/bin/bash', '-c', '/bin/bash -c echo foo bar' ], args: [ '/bin/bash', '-c', 'echo foo bar' ],
How often does it reproduce? Is there a required condition?
It always reproduces.
What is the expected behavior?
child_process.execFileSync
and child_process.execFile
invoke commands in the same way given the same arguments. In particular, I believe the behaviour of execFileSync
is expected.
What do you see instead?
child_process.execFileSync
and child_process.execFile
invoke commands in different ways given the same arguments.
Additional information
This bug reports follows from a discussion in #29466 - in particular the discussion starting with this comment of mine. This bug report is based on @bnoordhuis' comment in that thread.
I tested and was able to reproduce this bug on Node v16.15.0 and v18.3.0.