doc: fix copy node executable in Windows#48624
Merged
nodejs-github-bot merged 3 commits intonodejs:mainfrom Jul 6, 2023
Merged
doc: fix copy node executable in Windows#48624nodejs-github-bot merged 3 commits intonodejs:mainfrom
nodejs-github-bot merged 3 commits intonodejs:mainfrom
Conversation
Windows where command lists all places it finds a pattern in Path. The first one is the one that executes when called. So the old code was overriding the first executable by any other match.
Collaborator
|
Review requested:
|
Found a much easier solution for copying the node executable using native node. Can probably be consolidated to all OSs.
Member
|
Nice catch, thanks! Might make the docs simpler if we used the same command for both powershell and cmd. We could use the same thing for non-Windows too if we remove the |
Contributor
Author
|
Right, the same command can apply to both powershell and cmd. |
Member
|
I'm personally okay with both. Does anyone else have a preference? If not, I think it's fine to only update the Windows commands and unify both the cmd and powershell parts into the one you suggested. |
Merged command for both PowerShell and Command Prompt
aymen94
approved these changes
Jul 4, 2023
lpinca
approved these changes
Jul 6, 2023
Collaborator
|
Landed in d9438cc |
juanarbol
pushed a commit
that referenced
this pull request
Jul 13, 2023
Windows where command lists all places it finds a pattern in Path. The first one is the one that executes when called. So the old code was overriding the first executable by any other match. PR-URL: #48624 Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Merged
Ceres6
pushed a commit
to Ceres6/node
that referenced
this pull request
Aug 14, 2023
Windows where command lists all places it finds a pattern in Path. The first one is the one that executes when called. So the old code was overriding the first executable by any other match. PR-URL: nodejs#48624 Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Ceres6
pushed a commit
to Ceres6/node
that referenced
this pull request
Aug 14, 2023
Windows where command lists all places it finds a pattern in Path. The first one is the one that executes when called. So the old code was overriding the first executable by any other match. PR-URL: nodejs#48624 Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Member
|
This commit does not land cleanly on |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug description
The Windows
wherecommand looks for a pattern in the %Path% and lists all matches.The first match is the one that gets executed when called.
The problem with the current code is that if
wherefinds more than one match, theforloop will copy each of them.The result will be having the last match instead of the first one.
I encountered this when I tried to create a single executable application via GitHub Actions.
I was using a simple action configuration file:
But still, after copying the node executable using
Log showed:
And running
Got:
Fix description
node -e "require('fs').copyFileSync(process.execPath, 'hello.exe')"Explanation:
process.execPathgives the absolute pathname of the executable that started the Node.js processnode -eevaluates the content inside the quotationsrequire('fs')loads thefsmodulecopyFileSyncdoes the file copyThis solution should be valid for any other OS.
However, tested it on Windows only.