4

I've been using Ubuntu all my life, but today I've been given a different machine installed with Windows 10. I've an Angular project and I want to do the following things. All these in a separate terminal:

  1. Navigate into project folder and run code . so that I can see the code on Visual studio.

  2. Navigate into project folder and run ng serve to launch my application and keep it running.

  3. Navigate into project folder and run node server.js to start backend server and keep it running.

    this is very painful as the project location is-

C:\Users\tanzeel\Downloads\social-coder

Navigating again and again with a new terminal is what wasting my time. I decided to write a batch file so that I can do all at once with one single click. This is what my starter.bat file contains:

cd C:\Users\tanzeel\Downloads\social-coder\application 2>nul && call npm.cmd start
node C:\Users\tanzeel\Downloads\social-coder\server\server.js
code C:\Users\tanzeel\Downloads\social-coder

All of the above 3 commands works perfectly If I manually copy-paste them in separate terminals. But when I try to run them from batch file the problem is only first command is executed.I don't know other two are simply ignored or what. I'm coming from:

  1. How to run multiple commands in a batch file?
  2. How to run multiple commands in one batch file?

I admit that I'm a newbie and there are gaps in my knowledge. Please correct me.

Community
  • 1
  • 1
Tanzeel
  • 4,174
  • 13
  • 57
  • 110

1 Answers1

7

You need to use e.g. START to spawn new processes, otherwise the currently running program will just block until it's finished. It looks to me that this is what you want:

@ECHO OFF
CD C:\Users\tanzeel\Downloads\social-coder
START code .
CD application
START npm start
CD ..\server
START node server.js
EXIT
zb226
  • 9,586
  • 6
  • 49
  • 79
  • Ok I'll try this solution. But I've already tried `CALL`, `PUSHD` and `START "" /WAIT`. Maybe my implementation was wrong. So I'll try yours. Give me 2 mins please. – Tanzeel Jan 23 '20 at 11:01
  • 1
    @Tanzeel: take your time. a good resource for all things windows shell is ss64, here for example [the page on the `START` command](https://ss64.com/nt/start.html). – zb226 Jan 23 '20 at 11:02
  • This solution worked like a magic wand. But there is one tiny problem. 1) I'm getting one extra terminal with `C:\Users\tanzeel\Downloads\social-coder>` Can you fix this please :-) – Tanzeel Jan 23 '20 at 11:10
  • @Tanzeel: looks like this is the window of the batch script itself. this can be closed down with the `EXIT` command. also, if you're just running the script via a link on the desktop, and not via the shell, then the use `PUSHD`/`POPD` is not really needed. – zb226 Jan 23 '20 at 11:45
  • 1
    I'm still getting and extra terminal. But leave it. I'll deal with it. That's not a big issue. You've already solved my main problem. thanks :-) – Tanzeel Jan 24 '20 at 04:45