I have this partial batch, but it gives me an error (On 64 bit installations)
SETLOCAL EnableDelayedExpansion
REM Figure out what ProgramFiles Root we run the command
SET ProgFiles86Root=%ProgramFiles(x86)%
IF NOT "%ProgFiles86Root%"=="" GOTO win64
SET ProgFiles86Root=%ProgramFiles%
:win64
REM Get the Last installation of MVS
FOR /f "tokens=*" %%G in ('dir /b /a:d "%ProgFiles86Root%\Microsoft Visual Studio *"') do set NEWPATH=%PATH%;%ProgFiles86Root%\%%G\Common7\IDE
REM Find Tf in existing PATH + latest rev of MVS
FOR %%X in (tf.exe) do (set TFEXE=%%~$NEWPATH:X)
FOR /f "tokens=1" %%a IN ('"%TFEXE%" history . /r /noprompt /stopafter:1 /Version:W ^| FINDSTR /R "^[0-9][0-9]*"') do set TFS_BUILD=%%a
The last line fails with various errors depending on how I quote or escape TFEXE as %TFEXE% or !TFEXE! with errors like:
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
or
\Microsoft was unexpected at this time.
Note that TFEXE expands to:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\TF.exe
I know I can do this with a temporary file but I'm trying to avoid the use of any temporary files and only use a pipe to retrieve the token for setting the end variable TFS_BUILD