How to run two commands in an executable file in different folders?
P粉469090753
P粉469090753 2023-09-04 18:27:39
0
1
648
<p>I'm trying to create an executable that runs two commands in two different folders. </p> <p>I am developing using React application and Express API, they are located in two different folders. I tried creating a <code>.bat</code> file, running <code>npm run dev</code> in my API folder, and then opening a new terminal, in my application folder I run <code>npm start</code> but I can't get it to work. </p> <p>It is important to open two terminals to keep both processes running. </p> <p>My current code is as follows: </p> <pre class="brush:php;toolbar:false;">@echo off rem changes directory and runs the command in the current command prompt cd "path\one\" echo run 'npm run dev' in the current command prompt start cmd /c "npm run dev" rem opens a new command prompt window, changes directory and runs the command start cmd /k "cd path\two && echo Run 'npm start' && npm start"</pre> in a new command prompt <p>After running it, it just says that the specified path cannot be found. </p> <p>Any help would be greatly appreciated! </p>
P粉469090753
P粉469090753

reply all(1)
P粉481366803

Thanks so much Mofi, I finally got it working!

This is the code I use:

The bug pointed out by Mofi has been fixed

@echo off

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

Thanks again! Now I have to figure out how to run npm i in both paths and run other commands after npm i is finished.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template