-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
child_process: control argv0 for spawned processes
In some cases it useful to control the value of `argv[0]`, c.f. - https://github.com/andrewffff/child_process_with_argv0 - https://github.com/andrep/argv0 This patch adds explicit support for setting the value of `argv[0]` when spawning a process. PR-URL: #7696 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
Showing
3 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict'; | ||
require('../common'); | ||
const assert = require('assert'); | ||
const cp = require('child_process'); | ||
|
||
// This test spawns itself with an argument to indicate when it is a child to | ||
// easily and portably print the value of argv[0] | ||
if (process.argv[2] === 'child') { | ||
console.log(process.argv0); | ||
return; | ||
} | ||
|
||
const noArgv0 = cp.spawnSync(process.execPath, [__filename, 'child']); | ||
assert.strictEqual(noArgv0.stdout.toString().trim(), process.execPath); | ||
|
||
const withArgv0 = cp.spawnSync(process.execPath, [__filename, 'child'], | ||
{argv0: 'withArgv0'}); | ||
assert.strictEqual(withArgv0.stdout.toString().trim(), 'withArgv0'); |