Save the result of a command in variable, Windows batch
问题 I am trying to write a batch script that saves the result of a command in a variable. so I can use it later. For example I am tryin to run this on the script: sc queryex "Service" |find /i "pid" but I want to save this result in a variable. set PIDRS=sc queryex "Themes" |find /i "pid" ECHO "%PIDRS% Any Ideas? 回答1: for /f "tokens=* delims=" %%# in ('sc queryex "Themes" ^|find /i "pid"') do set "PIDRS=%%#" echo %PIDRS% This will set the entire line to PIDRS here's how to get only the pid: @echo