Gets bat return value

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/zidielang/article/details/53860255

In the bat, we need some command return value is stored as a variable,

After repeated testing, and finally come to a normal result

@echo off

setlocal enabledelayedexpansion 
for /f "usebackq skip=1 delims=" %%i in (`wmic ENVIRONMENT WHERE "Name='path'and UserName='%computername%\\%username%'" GET VariableValue`) do (
set var=%%i
echo !var!
pause

)

The results are as follows


Parsing:

1, setlocal enabledelayedexpansion    is to expand the local environment variable delay, otherwise it will show " ECHO is off ."

set: Set 
local: Local (environment variables) 
enable: can be 
delayed: delay 
expansion: Extended 
setlocal enabledelayedexpansion 

2, the loop usebackq for brackets with marks (with a key ~) instead of single quotation marks'

. 3, Skip Skip first row = 1, for the present example because there are typing the title bar, so removing the first row, started to take the output from the second line

. 4, %% i represents a variable number bis%, cmd expressed in% i, case sensitive while %% i %% I and different

. 5, ! Var! Open after a time delay in the variable enclose

Guess you like

Origin blog.csdn.net/zidielang/article/details/53860255