我想在变量中捕获processID,但是我收到错误,谢谢......
wmic process where name="notepad.exe" get ProcessId
ProcessID
7948
for /f %%a IN ('wmic process where name="notepad.exe" get ProcessId') do set "MYVAL=%%a"
echo %MYVAL%
notepad.exe - Invalid alias verb
答案 0 :(得分:3)
试试这个
for /f "usebackq" %%a IN (`wmic process where "name='notepad.exe'" get ProcessId`) do @echo %%a
修改强>
得到pid:
for /f "skip=1 usebackq" %%a IN (`wmic process where "name='notepad.exe'" get ProcessId`) do (
rem @echo %%a
if "%%a" neq "" set "pid=%%~a"
)
等号必须放在双引号中,因为它是批处理语法中的默认分隔符之一。