如何编写一个.bat文件来自动启动不同的代码仓库?

huangapple go评论62阅读模式
英文:

How to write a .bat file to automate starting to different repos?

问题

背景:

我正在处理两个不同的代码仓库。要启动这个应用程序,我必须在每个仓库上运行一些npm命令,然后在每个仓库上运行npm run start。我尝试编写一个.bat文件来自动化这个过程。这个.bat文件看起来像这样:

.bat文件:

echo "导航到仓库 #1..."
cd path\to\first\repo
echo "启动 Docker..."
npm run docker:start
echo "启动仓库 #1..."
npm start
echo "导航到仓库 #2..."
cd path\to\second\repo
echo "启动仓库 #2..."
npm start

当双击这个.bat文件时,命令会执行直到(包括)第6行。这是因为一旦第一个服务器启动,就会有一个进程持续运行以监听该服务器的更改,而不返回任何内容。因此,实际上,执行器永远无法超过第6行,第7行及以后的命令都不会执行。

问题是:
我如何编辑这个.bat文件,以便我可以在两个仓库上运行npm start

注意:
顺序很重要。因此,在启动仓库 #2 之前必须已经启动了仓库 #1。

英文:

Background:

I am working on two different repositories. To start up the app, I have to run a few npm commands on each repositories and then run npm run start on each. I tried to write a .bat file to automate this process. This .bat looks something like this:

.bat file:

echo "Navigating to repo #1..."
cd path\to\first\repo
echo "Starting docker..."
npm run docker:start
echo "Starting repo #1..."
npm start
echo "Navigating to repo #2..."
cd path\to\second\repo
echo "Starting repo #2..."
npm start

When double-clicking this .bat file, the commands get executed until (and including) line #6. This is because once the first server starts, a process keeps running to watch changes on this server without returning anything. So in fact, the executer never gets past line #6; and lines #7 forward never get executed.

The question is:
How can I edit this .bat file, so that I can run npm start on both repos?

Note that:
The order is important. So repo #1 has to have been started before starting repo #2.

答案1

得分: 1

start 是你的朋友。

阅读 help start 并尝试:

echo "导航到仓库 #1..."
cd path\to\first\repo

echo "启动 Docker..."
npm run docker:start

start "repo1" npm start

echo "导航到仓库 #2..."
cd path\to\second\repo
start "repo 2" npm start
英文:

start is your friend.

Read help start and try

echo "Navigating to repo #1..."
cd path\to\first\repo

echo "Starting docker..."
npm run docker:start

start "repo1" npm start

echo "Navigating to repo #2..."
cd path\to\second\repo
start "repo 2" npm start

</details>



huangapple
  • 本文由 发表于 2023年7月31日 19:55:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76803360.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定