Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
803 views
in Technique[技术] by (71.8m points)

windows - How to get PID of process just started from within a batch file?

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 multiple processes in parallel:

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

Example:

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

Obtain the PID of the processes (optional):

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

Kill the processes:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...