Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 519
Sergey V. Pereslavtsev Avatar asked Feb 28 '12 17:02

Sergey V. Pereslavtsev


People also ask

How do I find the PID of a process?

Task Manager can be opened in a number of ways, but the simplest is to select Ctrl+Alt+Delete, and then select Task Manager. In Windows, first click More details to expand the information displayed. From the Processes tab, select Details to see the process ID listed in the PID column.

Why do batch files start with @echo off?

If used in a batch file, echo on and echo off don't affect the setting at the command prompt. To prevent echoing a particular command in a batch file, insert an @ sign in front of the command. To prevent echoing all commands in a batch file, include the echo off command at the beginning of the file.


1 Answers

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 
like image 179
zappee Avatar answered Sep 30 '22 16:09

zappee