0

I have the following cmd that produces one line as an output and I would like to get the PID (the last column) from it.

netstat -anon | findstr 0.0.0.0:8088

netstat output:

  TCP    0.0.0.0:8088           0.0.0.0:0              LISTENING       6348

What I want: 6348

I want to use this in a batch file to dump the memory of this java process

njminchin
  • 408
  • 3
  • 13

1 Answers1

2
for /f "delims=" %%b in ('netstat -anon ^| findstr 0.0.0.0:8088') do for %%c in (%%b) do set "pid=%%c"
echo pid=%pid%
Magoo
  • 77,302
  • 8
  • 62
  • 84
  • It seems I forgot to mark your solution, sorry! there's a typo in there which I've fixed up (additional random ' before netstat). But thanks for the answer! – njminchin Mar 24 '23 at 06:19
  • Have to disagree with your edit - The quote should be matched before the `)` - without that string in single-quotes, the code posted would report that it couldn't find the file `netstat` – Magoo Mar 24 '23 at 07:34
  • Hmm, you're right... the ending apostrophe was missing and I thought I removed the starting one, but now I look again, I added the ending one. – njminchin Mar 27 '23 at 00:59