Skip to content

feat: add execve() to replace the current process with a command - #175

Open
Finomosec wants to merge 1 commit into
npm:mainfrom
Finomosec:execve
Open

Finomosec wants to merge 1 commit into
npm:mainfrom
Finomosec:execve

Conversation

@Finomosec

@Finomosec Finomosec commented Oct 27, 2026 •

Copy link
Copy Markdown

Adds promiseSpawn.execve(cmd, args, opts) and promiseSpawn.canExecve().

execve() builds the command exactly like the shell branch of promiseSpawn() (same escape.sh quoting, same opts.shell / opts.env / opts.cwd handling), but instead of spawning a child it replaces the current process with process.execve().
Before handing over it flushes stdout/stderr and puts stdio back into blocking mode.
The latter is a workaround for nodejs/node#66824: process.execve() passes stdio on in O_NONBLOCK, so programs that expect blocking writes fail with EAGAIN as soon as a pipe buffer fills up.
Setting the mode again is a no-op once Node.js fixes this itself.

canExecve() is false on Windows, where process.execve() does not exist; callers use it to fall back to promiseSpawn().

This is the building block for npm/cli#10165 (npx keeping an idle npm process alive for the whole lifetime of the command).
Follow-ups: npm/run-script#283 and npm/cli#10166.

Tested with the full suite (100 % coverage) on Node.js 22, 24 and 26.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant