`npm` innerhalb von einem bat-File braucht `call`, aber dann sieht man nur wie die 1 Zeile ausgeführt wird?

Hallo zusammen

Wenn ich in einem Windows-Batch kein call bei mehreren npm-Zeilen verwende, dann führt npm dazu dass nach der 1. npm-Zeile des batch-Files die Verarbeitung abgebrochen wird - die Stapelverarbeitung läuft also nicht mehr weiter.

(So nebenbei und meine persönliche Meinung zu diesem Kran: Wie behämmert ist denn sowas, WTF, dümmer könnte man es wohl nicht machen?!?)

Wenn ich vor jede npm-Zeile ein call reinmache, dann werden zwar alle Zeilen ausgeführt aber im Konsolenfenster sieht man nur den ersten Eintrag als call npm ... :

Batch:

@echo on
call npm install cordova-plugin-build-architecture

call npm install -g @angular/cli
call npm install -g @ionic/cli
call npm install -g cordova
call npm install -g native-run


pause

Ausgabe:

C:\Users\user1\Desktop\GIT\qr-code-app>call npm install cordova-plugin-build-architecture
npm WARN karma-jasmine-html-reporter@1.5.1 requires a peer of jasmine-core@>=3.5 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules\webpack-dev-server\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.11: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules\watchpack\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.11: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules\karma\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.11: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules\@angular\compiler-cli\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.11: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.2 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ cordova-plugin-build-architecture@1.0.6
updated 1 package and audited 19311 packages in 10.55s

26 packages are looking for funding
  run `npm fund` for details

found 79 vulnerabilities (78 low, 1 moderate)
  run `npm audit fix` to fix them, or `npm audit` for details
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
C:\Users\user1\AppData\Roaming\npm\ng -> C:\Users\user1\AppData\Roaming\npm\node_modules\@angular\cli\bin\ng

> @angular/cli@9.1.2 postinstall C:\Users\user1\AppData\Roaming\npm\node_modules\@angular\cli
> node ./bin/postinstall/script.js

+ @angular/cli@9.1.2
updated 1 package in 7.536s
C:\Users\user1\AppData\Roaming\npm\ionic -> C:\Users\user1\AppData\Roaming\npm\node_modules\@ionic\cli\bin\ionic
+ @ionic/cli@6.6.0
updated 1 package in 4.402s
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
C:\Users\user1\AppData\Roaming\npm\cordova -> C:\Users\user1\AppData\Roaming\npm\node_modules\cordova\bin\cordova
+ cordova@9.0.0
updated 1 package in 8.639s
C:\Users\user1\AppData\Roaming\npm\native-run -> C:\Users\user1\AppData\Roaming\npm\node_modules\native-run\bin\native-run
+ native-run@1.0.0
updated 1 package in 0.986s
Drücken Sie eine beliebige Taste . . .

…vom einen Quatsch zum anderen könnte man da wohl problemlos sagen!

Vielleicht weiss jemand, was das Ganze soll und wie man es bewerkstelligt dass bei der Ausführung des batches angezeigt wird welche npm-Zile nun dran ist. (Wie normal, wenn man kein call verwendet in Kombination mit Befehlen welche zu keinem Abbruch führen…)

Vielen Dank.

Seltsam. Wenn ich raten sollte, würde ich tippen, dass diese magische Fortschritsbalken-Ausgabe da etwas kaputt macht…

Nicht ganz ernst gemeint: Wenn man die hier als npmFunction.bat dazu legt…

@echo off
REM Partially from https://stackoverflow.com/a/935681

set RESTVAR=%1
shift
:loop1
if "%1"=="" goto after_loop
set RESTVAR=%RESTVAR% %1
shift
goto loop1

:after_loop
echo %RESTVAR%
call %RESTVAR%

… und dann in der Haupt-BAT schreibt

@echo on
call npmFunction npm install cordova-plugin-build-architecture
call npmFunction npm install -g @angular/cli
call npmFunction npm install -g @ionic/cli

pause

…dann gibt er es aus. Aber eigentlich sollte man sich sowas nicht antun müssen…

1 „Gefällt mir“

Danke fürs Feedback! :slight_smile:

Das Problem tritt in der PowerShell von Visual Studio Code auf, werde aber noch kurz schauen wie es sich in der „normalen“ Konsole (cmd) verhält…

Ja, gleiches Verhalten auch bei der „normalen“ cmd-Konsole:

C:\Users\user1\Desktop\GIT\qr-code-app>call npm uninstall -g native-run removed 30 packages in 0.337s removed 434 packages in 3.468s removed 227 packages in 2.31s removed 272 packages in 2.813s npm WARN karma-jasmine-html-reporter@1.5.1 requires a peer of jasmine-core@>=3.5 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules\webpack-dev-server\node_modules\fsevents):npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.11: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"}) npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules\watchpack\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.11: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"}) npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules\karma\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.11: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"}) npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules\@angular\compiler-cli\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.11: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"}) npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.2 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

removed 1 package and audited 19310 packages in 9.232s

26 packages are looking for funding
  run `npm fund` for details

found 79 vulnerabilities (78 low, 1 moderate)
  run `npm audit fix` to fix them, or `npm audit` for details Drücken Sie eine beliebige Taste . . .

In einem anderen Forum wurde mir gesage man können die Packages auch alle mit einer Zeile installieren resp. deinstallieren. Wäre ein Workaround, aber meine Frage ist da eher genereller Natur.£

Werde den Vorschlag von dir nun auch kurz testen…

Funktioniert bestens, super stabile Lösung des Problems, was will man mehr?

Vielen Dank!! :slight_smile: