7

I want to grep the the PID of last running process in Windows. I am running the command in the background.

  • start "Window Title" /b "c:\Program Files\Wireshark\tshark.exe" -i 1 -w file1.pcap
  • start "Window Title" /b "c:\Program Files\Wireshark\tshark.exe" -i 1 -w file2.pcap

How do I get the PIDs of these commands?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user87005
  • 964
  • 3
  • 10
  • 27

2 Answers2

4

Possibly by tracking them.

When you start the first instance, you could use the tasklist command with the filter by the image name (see tasklist /?) to find the PID, which you would then store somewhere. (The output of tasklist can be parsed with the FOR /F command, see FOR /? for more info.)

Then, when you run the second instance, you do the same, but additionally filter out the stored PID (for example, using FIND /V, see FIND /? for more help), so you get only new instance's PID. Store it as well to use later like the first one when you need to run a third instance.

Andriy M
  • 76,112
  • 17
  • 94
  • 154
3

You can use wmic to launch the processes and get the pid from that. I've posted what I use for this as an answer to a similar question here.

Community
  • 1
  • 1
kybernetikos
  • 8,281
  • 1
  • 46
  • 54