windows – 批处理文件提取字符串部分

前端之家收集整理的这篇文章主要介绍了windows – 批处理文件提取字符串部分前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有这个窗口的批处理命令:

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

它返回此字符串

(spaces)  ProcessId = 13764;

而且我只需要在变量中存储pid号(13764),我该怎么办?

解决方法

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

方法返回行中的最后一个单词,因此它也可以在开头的可变数量的单词的其他行中使用.

猜你在找的Windows相关文章