|
43 | 43 |
|
44 | 44 | startup.processRawDebug(); |
45 | 45 |
|
46 | | - startup.resolveArgv0(); |
| 46 | + process.argv[0] = process.execPath; |
47 | 47 |
|
48 | 48 | // There are various modes that Node can run in. The most common two |
49 | 49 | // are running from a script and running the REPL - but there are a few |
|
459 | 459 | function evalScript(name) { |
460 | 460 | var Module = NativeModule.require('module'); |
461 | 461 | var path = NativeModule.require('path'); |
462 | | - var cwd = process.cwd(); |
| 462 | + |
| 463 | + try { |
| 464 | + var cwd = process.cwd(); |
| 465 | + } catch (e) { |
| 466 | + // getcwd(3) can fail if the current working directory has been deleted. |
| 467 | + // Fall back to the directory name of the (absolute) executable path. |
| 468 | + // It's not really correct but what are the alternatives? |
| 469 | + var cwd = path.dirname(process.execPath); |
| 470 | + } |
463 | 471 |
|
464 | 472 | var module = new Module(name); |
465 | 473 | module.filename = path.join(cwd, name); |
|
764 | 772 | }; |
765 | 773 | }; |
766 | 774 |
|
767 | | - |
768 | | - startup.resolveArgv0 = function() { |
769 | | - var cwd = process.cwd(); |
770 | | - var isWindows = process.platform === 'win32'; |
771 | | - |
772 | | - // Make process.argv[0] into a full path, but only touch argv[0] if it's |
773 | | - // not a system $PATH lookup. |
774 | | - // TODO: Make this work on Windows as well. Note that "node" might |
775 | | - // execute cwd\node.exe, or some %PATH%\node.exe on Windows, |
776 | | - // and that every directory has its own cwd, so d:node.exe is valid. |
777 | | - var argv0 = process.argv[0]; |
778 | | - if (!isWindows && argv0.indexOf('/') !== -1 && argv0.charAt(0) !== '/') { |
779 | | - var path = NativeModule.require('path'); |
780 | | - process.argv[0] = path.join(cwd, process.argv[0]); |
781 | | - } |
782 | | - }; |
783 | | - |
784 | 775 | // Below you find a minimal module system, which is used to load the node |
785 | 776 | // core modules found in lib/*.js. All core modules are compiled into the |
786 | 777 | // node binary, so they can be loaded faster. |
|
0 commit comments