[Batch file] - Output of a command to variable
If you want to set the output of a command to a value you have to capture it in a for statement like this: for /f "tokens=2 delims=:" %%a in ('systeminfo ^| find "OS Name"') do set OS_Name=%%a Then remove the leading spaces like this: (there is probably a better way to do this) for /f "tokens=* delims= " %%a in ("%OS_Name%") do set OS_Name=%%a A few things to note here: 1.) "tokens=2 delims=:" is setting the delimiter to : and it is selecting the second section only, which will pull only the part you want. 2.) the | is escaped with a ^ , this needs to be done in for loops or anything after that will attempt to execute as seperate commands. 3.) "tokens=* delims= " The token here is * which is all tokens. ======================= Examples of WMIC output to variables: echo WMIC output to variables for /f "usebackq tokens=1,2 delims==|" %%I in (`wmic os get name^,version /format:l...