如何从批处理文件中获取刚刚启动的进程的PID? [英] How to get PID of process just started from within a batch file?

查看:938
本文介绍了如何从批处理文件中获取刚刚启动的进程的PID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows批处理脚本中,有start命令可以启动新进程.

In Windows batch scripting there is start command which starts a new process.

是否可以获取刚刚开始的进程的PID?

Is it possible to get PID of the process just started?

推荐答案

这是一篇旧文章,但我认为值得分享以下在Windows上现在可以正常使用的易于使用"的解决方案.

This is an old post but I think that it worth to share the following 'easy to use' solution which works fine nowadays on Windows.

并行启动多个进程:

start "<window title>" <command will be executed>

示例:

start "service1" mvn clean spring-boot:run
start "service2" mvn clean spring-boot:run

获取进程的PID(可选):

tasklist /V /FI "WindowTitle eq service1*"
tasklist /V /FI "WindowTitle eq service2*"

终止进程:

taskkill /FI "WindowTitle eq service1*" /T /F
taskkill /FI "WindowTitle eq service2*" /T /F

这篇关于如何从批处理文件中获取刚刚启动的进程的PID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆