最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

windows - How can I ensure port is released when I shut down batch process? - Stack Overflow

programmeradmin2浏览0评论

I have a batch file that looks like this:

cd application1\backend\application1
start cmd /k "color 0F & npm run start"
cd ../../..

It consists of a series of these blocks, going in and out of several directories and starting node applications in each (and coloring the terminal it opens to run them).

What I've noticed is that when I shut down the terminal by killing it, or by killing the entire batch of them by right-clicking the icon in the system tray and selecting "Close all Windows", sometimes the ports they listen on remain in use. I get this error when I try to run them again:

Error: listen EADDRINUSE: address already in use ::1:3008

How can I ensure that when I shut down the terminals, the ports are released. I'm looking for something I can add to the batch file, like a flag I can add to starting the node application. Something like this:

start cmd /k /release-port-on-close "npm run start"

I'm also looking for a way that doesn't require manually shutting down each terminal one at a time, like hitting ctrl-c on each terminal.

Is there such a way?

I'm running Windows 10.

发布评论

评论列表(0)

  1. 暂无评论