spacecodeur
spacecodeur

Reputation: 2406

Script Batch, run external exe and get his PID

I have a batch script A. This script run an .exe application and after a while, the script A stop the .exe application. My problem is I run my script A in several shell. Consequently, I execute several times simultaneously the same .exe application (but with different PID)

My question is, in batch, how can I run an external .exe and get his PID ? If I run the exe and I catch his PID, I can stop the "good" .exe.

Upvotes: 1

Views: 177

Answers (1)

Noodles
Noodles

Reputation: 26

For /f "tokens=2 delims=;= " %A in ('wmic process call create notepad.exe ^| findstr /c:ProcessId') Do Echo %A

For is the command to get output from a command. WMIC returns the PID for programs it starts.

 wmic process call create notepad.exe 

In a batch file use %%A rather than %A when typing.

Upvotes: 1

Related Questions