Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On windows generated *.cmd file overwrites console window title #4239

Open
cdmahoney opened this issue Jan 17, 2022 · 2 comments
Open

On windows generated *.cmd file overwrites console window title #4239

cdmahoney opened this issue Jan 17, 2022 · 2 comments
Labels
Bug thing that needs fixing Needs Triage needs review for next steps platform:windows is Windows-specific Release 8.x work is associated with a specific npm 8 release

Comments

@cdmahoney
Copy link

With npm 8.3.1 the *.cmd file generated to run node applications overwrites the current console window title, setting the title to c:\Windows\system32\cmd.exe (the value of the %COMSPEC% environment variable) on exiting the application.

Sample of generated command file:

@ECHO off
GOTO start
:find_dp0
SET dp0=%~dp0
EXIT /b
:start
SETLOCAL
CALL :find_dp0

IF EXIST "%dp0%\node.exe" (
  SET "_prog=%dp0%\node.exe"
) ELSE (
  SET "_prog=node"
  SET PATHEXT=%PATHEXT:;.JS;=;%
)

endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%"  "%dp0%\node_modules\npm-test-cmd\npm-test-cmd.js" %*

This is extremely annoying if you have various console windows open and have set titles to help distinguish between them.

@cdmahoney
Copy link
Author

I've been doing some more testing and found another problem with the *.cmd files generated by npm. The line:
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\node_modules\npm-test-cmd\npm-test-cmd.js" %*

calls node to execute the javascript file, the problem is that the trick of using goto #_undefined_# 2>NUL means that the node execution environment does not inherent the current environment. So if as in my case you are calling the cmd file from a batch file which locally modifies environment variables, these variables will not be inheritable by the node process and may cause the process to fail.

This happens, for example, when using cordova and calling cordova.cmd compile android from a batch file which locally sets the JAVA_HOME environment variable - the node process does not inherit the value of JAVA_HOME and the compilation fails.

This could break an awful lot of work flows.

@darcyclarke darcyclarke added Release 8.x work is associated with a specific npm 8 release Needs Triage needs review for next steps platform:windows is Windows-specific Bug thing that needs fixing labels Mar 25, 2022
@jclab-joseph
Copy link

jclab-joseph commented Jun 22, 2022

endLocal & goto #_undefined_# 2>NUL ||
This is also a big problem.

If start with setlocal in the parent bat file and then cd(change directory).
js file reports invalid process.cwd() .

=> npm/cmd-shim#69

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps platform:windows is Windows-specific Release 8.x work is associated with a specific npm 8 release
Projects
None yet
Development

No branches or pull requests

3 participants