Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.
January 8, 2000
A. Some programs return values to the command line and it may be youwant these in a variable so they can be viewed/queried by other processes.
The easiest way to put the result into an environment variable is to trap itin a FOR statement.
For /f "Tokens=*" %i in ('command') do setvariable="%i"
For example:
C:>For /f "Tokens=*" %i in ('ver') do set NTVersion="%i"
C:>set NTVersion="Windows NT Version 4.0 "
C:>echo %NTVersion%
"Windows NT Version 4.0 "
If you place the command in a batch file you require two % in front of i,e.g.
For /f "Tokens=*" %%i in ('ver') do set NTVersion="%%i"
You May Also Like