1

So I'm trying to make a small script to run my tomcat server and do npm run serve to start my vue project. But here is the problem if I open CMD and and cd into the project then I can do npm run serve and it does work but if I try to call it from a batch file it does not work. The vue app is in a folder called "test-app" Here are my batch files:

set CATALINA_HOME="C:\workspaces\apache-tomcat-8.5.39"
set PATH="%CATALINA_HOME%\bin"
set PATH=%APPDATA%\npm;%PATH%
start cmd /k call "C:\workspaces\apache-tomcat-8.5.39\bin\startup.bat"
start cmd /k call "test-app/webserver.bat"

webserver.bat:

cd test-app
call npm run serve

The tomcat server starts up all fine, but apparently this does not. here is the output:

C:\Users\Kenneth\Desktop\Start av servere>cd test-app

C:\Users\Kenneth\Desktop\Start av servere\test-app>call npm run serve
'npm' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Kenneth\Desktop\Start av servere\test-app>

I've also tried

cd test-app
start npm run serve

and

cd test-app
call npm run serve

aswell as

cd test-app
npm run serve
  • 1
    Please read my answer on [Why is no string output with 'echo %var%' after using 'set var = text' on command line?](https://stackoverflow.com/a/26388460/3074564) You have put first `"` at wrong position which is the reason why your code in question does not work. The first double quote must be left to variable name and not at beginning of value assigned to the variable. See also [How to set environment variables with spaces?](https://stackoverflow.com/a/34402887/3074564) – Mofi Jun 05 '19 at 09:17
  • 1
    And please read also entire answer on [What is the reason for "X is not recognized as an internal or external command, operable program or batch file"?](https://stackoverflow.com/a/41461002/3074564) You define __local__ `PATH` wrong resulting in the error message. – Mofi Jun 05 '19 at 09:19
  • The first three lines should be `set "CATALINA_HOME=C:\workspaces\apache-tomcat-8.5.39"` and `if "%PATH:~-1%" == ";" (set "Separator=") else set "Separator=;"` and `set "PATH=%PATH%%Separator%%CATALINA_HOME%\bin;%APPDATA%\npm"`. – Mofi Jun 05 '19 at 09:28
  • What do you want to achieve with the last two lines starting with `start cmd /k call`? You start a new command process with `start cmd /k` to execute a batch file. The command `call` is completely useless here. Once started second command process finished processing the specified batch file, the second command process keeps running for user actions. While second `cmd.exe` processes `startup.bat`, first `cmd.exe` processing main batch file immediately continues with execution of last command line which starts a third command process to process `webserver.bat` and then keeps also running. – Mofi Jun 05 '19 at 09:39
  • So before reaching end of main batch file three command processes are running parallel and then first command process ends after starting third command process and the other two command processes are parallel processing the two batch files and finally keep running until being closed by the user or on Windows shutdown. I have my doubts that this is what you really want. – Mofi Jun 05 '19 at 09:41

1 Answers1

0

I removed set PATH=%APPDATA%\npm;%PATH% and I added set PATH="C:\Program Files\nodejs" to the main batch file. So it looked like this instead:

echo "Vent litt så starter serverne - tar ca 2min for komplett oppstart. Ikke lukk vinduene som åpner."
set CATALINA_HOME="C:\workspaces\apache-tomcat-8.5.39"
set PATH="%CATALINA_HOME%\bin"
set PATH="C:\Program Files\nodejs"
start cmd /k call "C:\workspaces\apache-tomcat-8.5.39\bin\startup.bat"
start cmd /k call "test-app/webserver.bat"