How to run two commands in an executable file in different folders?
P粉469090753
2023-09-04 18:27:39
<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>
Thanks so much Mofi, I finally got it working!
This is the code I use:
The bug pointed out by Mofi has been fixed
Thanks again! Now I have to figure out how to run
npm i
in both paths and run other commands afternpm i
is finished.