@@ -4,7 +4,7 @@ const native = require('./index.js');
44 * Performs the execvp system call with the given file and arguments, replacing
55 * the current process image with the new one.
66 *
7- * This function does not return if successful, as the current process is
7+ * This function does not return if successful, as the current process image is
88 * replaced by the new one. An error may be thrown, with an error message
99 * containing the error code returned by execvp.
1010 *
@@ -15,12 +15,23 @@ const native = require('./index.js');
1515 * @param {string } file The file to execute. If not a path, the PATH environment
1616 * variable is searched.
1717 * @param {string[] } args The arguments to pass to the new process. The `file`
18- * argument is automatically prepended to the arguments.
18+ * argument is automatically prepended to the arguments
19+ * and passed as the first argument to the `execvp`
20+ * system call.
21+ * @param {Object } [options] Optional options.
22+ * @param {string } [options.arg0=file] The value to pass as the first argument
23+ * to the `execvp` system call. Defaults to
24+ * the `file` argument.
1925 * @throws {Error } If the execvp system call fails.
2026 */
21- module . exports . execvp = function ( file , args ) {
27+ module . exports . execvp = function ( file , args , options = { } ) {
28+ const arg0 = options . arg0 ?? file ;
29+
30+ // Prevent the standard streams from being closed when the process is
31+ // replaced.
2232 native . doNotCloseOnExit ( process . stdin . fd ) ;
2333 native . doNotCloseOnExit ( process . stdout . fd ) ;
2434 native . doNotCloseOnExit ( process . stderr . fd ) ;
25- native . execvp ( file , [ file , ...args ] ) ;
35+
36+ native . execvp ( file , [ arg0 , ...args ] ) ;
2637} ;
0 commit comments