mirror of https://github.com/lukechilds/node.git
Browse Source
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: https://github.com/nodejs/node/pull/7696 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>v7.x
Pat Pannuto
9 years ago
committed by
Anna Henningsen
3 changed files with 33 additions and 1 deletions
@ -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'); |
Loading…
Reference in new issue