Skip to content

Commit 6139c81

Browse files
committed
process: make execve's args argument optional
Align the code with the documentation and similar methods used to execute os commands - the `args` argument should be optional, and if omitted, treated as an empty array (`[]`). Fixes: #58411
1 parent 53944c4 commit 6139c81

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/internal/process/per_thread.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ function wrapProcessMethods(binding) {
279279
return true;
280280
}
281281

282-
function execve(execPath, args, env) {
282+
function execve(execPath, args = [], env) {
283283
emitExperimentalWarning('process.execve');
284284

285285
const { isMainThread } = require('internal/worker');
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
const { skip, isWindows, isIBMi } = require('../common');
4+
const { fail } = require('assert');
5+
const { isMainThread } = require('worker_threads');
6+
const { spawnSync } = require('child_process');
7+
8+
if (!isMainThread) {
9+
skip('process.execve is not available in Workers');
10+
} else if (isWindows || isIBMi) {
11+
skip('process.execve is not available in Windows or IBM i');
12+
}
13+
14+
// Get full path to the ps executable
15+
const psResult = spawnSync('which', ['ps'], { encoding: 'utf8' });
16+
if (psResult.error || !psResult.stdout) {
17+
skip('cannot determine location of ps executable, test will be skipped');
18+
}
19+
const psExecutable = psResult.stdout.trim();
20+
21+
process.execve(psExecutable);
22+
// If process.execve succeeds, this should never be executed.
23+
fail('process.execve failed');

0 commit comments

Comments
 (0)