加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

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

发布时间:2020-12-14 05:24:57 所属栏目:Windows 来源:网络整理
导读:我有这个窗口的批处理命令: wmic process call create "notepad.exe" | find "ProcessId" 它返回此字符串 (spaces) ProcessId = 13764; 而且我只需要在变量中存储pid号(13764),我该怎么办? 解决方法 for /F "delims=" %%a in ('wmic process call create "
我有这个窗口的批处理命令:

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%

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读