From 99f45b24763b80e116abaf5699082785d92e2d42 Mon Sep 17 00:00:00 2001 From: Pat Pannuto Date: Tue, 12 Jul 2016 22:04:19 -0400 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/7696 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell --- doc/api/child_process.md | 10 ++++++++++ lib/child_process.js | 6 +++++- .../parallel/test-child-process-spawn-argv0.js | 18 ++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-child-process-spawn-argv0.js diff --git a/doc/api/child_process.md b/doc/api/child_process.md index ab140bc65f..fe265afc12 100644 --- a/doc/api/child_process.md +++ b/doc/api/child_process.md @@ -295,6 +295,8 @@ added: v0.1.90 * `options` {Object} * `cwd` {String} Current working directory of the child process * `env` {Object} Environment key-value pairs + * `argv0` {String} Explicitly set the value of `argv[0]` sent to the child + process. This will be set to `command` if not specified. * `stdio` {Array|String} Child's stdio configuration. (See [`options.stdio`][`stdio`]) * `detached` {Boolean} Prepare child to run independently of its parent @@ -397,6 +399,14 @@ child.on('error', (err) => { }); ``` +*Note: Certain platforms (OS X, Linux) will use the value of `argv[0]` for the +process title while others (Windows, SunOS) will use `command`.* + +*Note: Node.js currently overwrites `argv[0]` with `process.execPath` on +startup, so `process.argv[0]` in a Node.js child process will not match the +`argv0` parameter passed to `spawn` from the parent, retrieve it with the +`process.argv0` property instead.* + #### options.detached