Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting log message from svnlook via windows batch

I try to prepare a post-commit hook for my svn repository. Therefore i need the log message from the last commit which I get with the command svnlook log -r %REV% %REPOS%. Filling the snippet with the appropriate params I get the following multline log message:

This
is
my
transaction.

This works well so far. Now I put this in a .bat file:

@ECHO OFF

REM just for testing purpose...
SET REPOS=C:\repo
SET REV=40

FOR /F %%i in ('svnlook log -r %REV% %REPOS%') do SET VAR=%%i

ECHO %VAR%

When I execute the script only the last line transaction. is echoed. The for-loop is a snippet from which I thought, it would read the svnlook output into %var%.

My approach is to get the log message in a variable, which I pass to another exe-file as parameter. But it won't work. I don't know how to properly use the loop.

The log message should given to another exe-file as an parameter.

I modified the script to the following (@thx PA.)

@ECHO OFF
setlocal enabledelayedexpansion

SET REPOS=C:\repo
SET REV=40

SET MSG=
FOR /F %%i in ('svnlook log -r %REV% %REPOS%') do SET VAR=!VAR! %%i
ECHO !VAR!

The output is now This is my transaction. But the linebreak are gone but I need the for further processing.

like image 367
Cornertrap Avatar asked Dec 07 '25 03:12

Cornertrap


2 Answers

As you want also the linebreaks, you can add them when concatenating the lines.

@ECHO OFF
setlocal enabledelayedexpansion
set LF=^


rem ** The two empty lines are NECESSARY

SET REPOS=C:\Users\CH.ROSESOFT\Downloads\t3\repo
SET REV=40

SET MSG=
FOR /F %%i in ('svnlook log -r %REV% %REPOS%') do (
    SET "VAR=!VAR!!LF!%%i"
    SET "PAR=!PAR!^^!LF!!LF!%%i"
)
ECHO !VAR!
myProgram.exe !par!
like image 178
jeb Avatar answered Dec 08 '25 21:12

jeb


If I understand your question correctly, you need to concatenate the output of the svnlook command into a single variable (something like VAR = VAR & %%i)

In BAT you access the contents of a variable by writing the variable wrapped with % signs. And you concatenate by just sticking them together. SET X=%A%. SET Y=%A%%B%. So in your case you should change the SET assignment to something like SET VAR=%VAR% %%i.

However, this would not work. As the assignment is inside a FOR loop, it needs to be reevaluated every iteration. You need to Enable Delayed Expansion. Read HELP SET for more information.

Something similar to this,

@ECHO OFF
setlocal enabledelayedexpansion
...
SET VAR=
FOR /F %%i in ('solook log -r %REV% %REPOS%') do SET VAR=!VAR! %%i
ECHO !VAR!
like image 23
PA. Avatar answered Dec 08 '25 21:12

PA.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!