Home > Software design >  How to run two commands in different folders from an executable file?
How to run two commands in different folders from an executable file?

Time:01-30

I'm trying to create an executable file that runs two commands in two different folders.

I'm working on a react app with an express API and they are in two different folders. I was trying to create a .bat file that ran npm run dev in my API folder and then open a new terminal to run npm start in my app folder but I can't get it to work.

It is important that in opens two terminals in order to keep both processes open.

My code right now is this

@echo off

rem Change directory and run command in current command prompt
cd "path\one\"
echo Running 'npm run dev' in current command prompt
start cmd /c "npm run dev"

rem Open new command prompt window and change directory and run command
start cmd /k "cd path\two && echo Running 'npm start' in new command prompt && npm start"

Once it runs, it just says it cant find the specified route.

Any help would be appreciated!

CodePudding user response:

Thanks a lot Mofi I finally got it working!

This is the code I used:

@echo off

@start start "npm start" /D"path1" %ComSpec% /D /C npm.cmd start
@start "npm start" /D"path2" %ComSpec% /D /K npm.cmd start

Once again thanks a lot! I now must figure out how to make it run npm i in both of them and run the other commands once npm i is over.

  • Related