0

Disclaimer: I have absolutely no coding experience in any language.

I need to create a script that can find the PID for a process, of which there will be multiple running, and then create a process dump for each PID. Procdump doesn't allow the process name to be used if more then one is running, so my goal is to to have the PID found for the process and then be set to variables for later commands.

Here is a .bat I have made:

for /F "tokens=2" %%K in ('
   tasklist /FI "ImageName eq T.exe" /FI "Status eq Running" /FO LIST ^| findstr /B "PID:"
') do (
   set  "X= %%K"
)




c:\Users\Public\Documents\Procdump\procdump.exe -ma %X%


pause

I am able to get the last PID set and used in a command, but I can't figure out how to get the first two.

This may seem like a lot of work for one go, but the later goal is for this to run every 2 and 5 hours for 24 hours. I have been able to get that to work so for now i just need to solve the PID problem. In hindsight, maybe powershell would have been a better choice, but i feel like i got close so I want to to see this route through.

There could be three processes max. I was thinking it would look something like this:

for /F "tokens=2" %%K in ('
   tasklist /FI "ImageName eq T.exe" /FI "Status eq Running" /FO LIST ^| findstr /B "PID:"
') do (
   set  "X= %%K"
   set  "Y=???"
   set  "Z=???"
)




c:\Users\Public\Documents\Procdump\procdump.exe -ma %X%
c:\Users\Public\Documents\Procdump\procdump.exe -ma %Y%
c:\Users\Public\Documents\Procdump\procdump.exe -ma %Z%


pause
Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • What about `call set "X=%%X%% %%K"` (given that there is `set "X="` somewhere before the `for /F` loop)? – aschipfl Jun 15 '21 at 15:04
  • 3
    If you need to execute `procdump.exe` nice per item, simply move it into the `for /F` loop with `-ma %%K` as the parameters… – aschipfl Jun 15 '21 at 15:08
  • Thank you aschipfl, that seems to work! Funny enough, I actually tried this early on and probably did it wrong! – recongodd44 Jun 15 '21 at 15:50
  • 2
    @recongodd44: Don't put "solved" in the title. If you found a solution, write an answer below, and you can even accept it. – Nicol Bolas Jun 15 '21 at 15:58

1 Answers1

0

If you need to execute procdump.exe nice per item, simply move it into the for /F loop with -ma %%K as the parameters