0

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

1 Answer 1

0

After some finagling I've found the formula that works.

FOR /f "tokens=1" %%g in ('"%TFEXE%" history . /r /noprompt /stopafter:1 /Version:W ^| findstr /R ^[0-9][0-9]*') do set TFS_BUILD=%%g

The question I have is why would quoting the regex in findstr cause the entire operation to fail. None the less, it works for me and I'm posting it for anyone else to have for surgically extracting output from an executable without the awkward use of storing it to a temp file.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .