Skip to content

Commit 59b004a

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 59b004a

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 execName = 'date';
16+
const execWhichResult = spawnSync('which', [execName], { encoding: 'utf8' });
17+
if (execWhichResult.error || !execWhichResult.stdout) {
18+
skip('cannot determine location of ps executable, test will be skipped');
19+
}
20+
const executable = execWhichResult.stdout.trim();
21+
22+
process.execve(executable);
23+
// If process.execve succeeds, this should never be executed.
24+
fail('process.execve failed');

0 commit comments

Comments
 (0)