4

I have this window's batch command:

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

It returns this string

(spaces)  ProcessId = 13764;

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

4

4 回答 4

2
for /f "tokens=2 delims=;= " %%P in ('wmic process call create "notepad.exe" ^| find "ProcessId"') do echo %%P
于 2013-05-28T08:56:48.093 回答
1
for /F "delims=" %%a in ('wmic process call create "notepad.exe" ^| find "ProcessId"') do (
   for %%b in (%%a) do set value=%%b
)
echo %value%

此方法返回该行中的最后一个单词,因此它也可以用于开头的单词数可变的其他行。

于 2013-05-28T13:33:48.973 回答
0
for /f  "tokens=3 delims=;=" %%a in ("(spaces)  ProcessId = 13764;") do set value=%%c
echo %value%
于 2013-05-28T09:06:12.523 回答
0

用这个:

echo %strContent:~6, -1%
于 2013-05-28T08:52:35.050 回答