Windows – Set environment variable to output of command in Windows command prompt

command linewindows

I have a file, build-version.txt, that contains the build number "1.2.3". I want to store this build number in an environment variable. In Unix, I would do something like:

version=$(cat build-version.txt)

How do I do this in Windows? The following doesn't do what I want:

set VERSION=type build-version.txt

Best Answer

Just use: set /P VERSION=< build-version.txt

and you can check with command: echo %VERSION%