Part of the batch file extraction line

I have a batch window command:

wmic process call create "notepad.exe" | find "ProcessId" 

It returns this string

 (spaces) ProcessId = 13764; 

And I need to save only pid number (13764) in the variable, how can I do this?

+4
source share
4 answers
 for /F "delims=" %%a in ('wmic process call create "notepad.exe" ^| find "ProcessId"') do ( for %%b in (%%a) do set value=%%b ) echo %value% 

This method returns the last word in a string, so it can be used on other lines with a variable number of words at the beginning.

+1
source
 for /f "tokens=2 delims=;= " %%P in ('wmic process call create "notepad.exe" ^| find "ProcessId"') do echo %%P 
+2
source

Use this:

 echo %strContent:~6, -1% 
0
source
 for /f "tokens=3 delims=;=" %%a in ("(spaces) ProcessId = 13764;") do set value=%%c echo %value% 
0
source

Source: https://habr.com/ru/post/1483107/


All Articles