windowsbatch-fileloggingmultilinesvnlook

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.


Solution

  • 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!