From 2f32191686d1be6b4c59784418bd24f46ae804c2 Mon Sep 17 00:00:00 2001 From: Pat Pannuto Date: Wed, 13 Jul 2016 20:18:22 -0400 Subject: [PATCH] process: save original argv[0] For historical and other reasons, node overwrites `argv[0]` on startup. See - 2c6f79c08, - https://github.com/nodejs/node/issues/7434 - https://github.com/nodejs/node/pull/7449 - https://github.com/nodejs/node/pull/7696 For cases where it may be useful, save the original value of `argv[0]` in `process.argv0` PR-URL: https://github.com/nodejs/node/pull/7696 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell --- doc/api/process.md | 23 ++++++++++++++++++++--- lib/internal/bootstrap_node.js | 5 +++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/doc/api/process.md b/doc/api/process.md index cb6a1814fcd8ec..436fcdb16a1ee6 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -457,9 +457,10 @@ added: v0.1.27 The `process.argv` property returns an array containing the command line arguments passed when the Node.js process was launched. The first element will -be [`process.execPath`]. The second element will be the path to the -JavaScript file being executed. The remaining elements will be any additional -command line arguments. +be [`process.execPath`]. See `process.argv0` if access to the original value of +`argv[0]` is needed. The second element will be the path to the JavaScript +file being executed. The remaining elements will be any additional command line +arguments. For example, assuming the following script for `process-args.js`: @@ -486,6 +487,22 @@ Would generate the output: 4: four ``` +## process.argv0 + + +The `process.argv0` property stores a read-only copy of the original value of +`argv[0]` passed when Node.js starts. + +```js +$ bash -c 'exec -a customArgv0 ./node' +> process.argv[0] +'/Volumes/code/external/node/out/Release/node' +> process.argv0 +'customArgv0' +``` + ## process.chdir(directory)