Laxmi
Laxmi

Reputation: 93

How to save output from svn log command to a variable and find a particular string?

I need to extract versionNo string from recent committed svn log using batch command.

I am using following commands,

cd C:\Program Files\TortoiseSVN\bin\
svn --username user --password pass log -r COMMITTED "SVN_PATH"

and it returns,

------------------------------------------------------------------------
r304 | user | 2019-06-10 17:53:23 +0530 (Mon, 10 Jun 2019) | 2 lines

versionNo - 1.2.3.4 committed for Mantis Id - 0000742
------------------------------------------------------------------------

I am not able to save this command result in a variable and extract this string (1.2.3.4).

Upvotes: 0

Views: 503

Answers (2)

aschipfl
aschipfl

Reputation: 34949

To capture the output of a command use the for /F loop.

I think the easiest way would be this:

cd /D "C:\Program Files\TortoiseSVN\bin"

for /F "tokens=2 delims=- " %%L in ('
    svn --username user --password pass log -r COMMITTED "SVN_PATH"
') do @set "VERSION=%%L"

echo/%VERSION%

Since - and SPACE are defined as token delimiters, the hyphen-only = delimiters-only lines are automatically ignored and no particular filtering (using find or findstr) is needed.

Upvotes: 2

SNR
SNR

Reputation: 772

I would do this, for instance,

setlocal

cd C:\Program Files\TortoiseSVN\bin\

for /f "tokens=3" %%G IN ('svn --username user --password pass log -r COMMITTED "SVN_PATH" ^| find "VersionNo"') do set "v=%%G"

echo %v%

endlocal

Upvotes: 1

Related Questions