I need some help with windows batch script
What am i trying to achieve:
- retrieve the youngest (last) revision from repository
- search for a particular string in that file
- if string exists, load a web page
What i have tried:
set REVNO=$(svnlook youngest D:\Subversion\...)
set REVURL=D:\Subversion\...\db\revprops\0\
findstr /m "string_I_am_searching_for" %REVURL%%REVNO%
if %errorlevel%==0 (
start http://webpage
)
Why am i trying to do this:
I want to start Hudson CI automatic test after a commit that has a particular string in message (ex. Autobuild: true
)
I am not able to debug my code, since i am unfamiliar with Windows batch scripting
In my script I used:
- Concatenation of variables (which might be wrong) because i was not sure if i can append variable to the path
findstr
to find if a file contains string (i know that findstr can be used on variables too)
I would not be surprised if my small script has semantic problems as well as syntactic problems, because, as I have already mentioned, I haven't done that much of batch scripting before
I have no requirements, no specifications, so the script may be implemented in any way possible. So i am open for suggestions
P.S. I have read also that using overweight procedures on post-commit
is not a good idea, because svn does not return controls back to the user until it is done with everything -> This is not a big problem
EDIT: I found by side testing that i didn't really aquire the youngest revision number, but rather used the command string. SO after googling a little more i found that it is not that easy in windows to call some command and store the result in variable. So i have decided to use file to store intermediate results.
This is what i have tried:
cd D:\Subversion\...\hooks
SET OUTPUT=testing
FOR /F "tokens=*" %a in ('revision.bat') do ( SET OUTPUT=%a )
findstr /m "o" D:\Subversion\...\db\revprops\0\%a
if %errorlevel%==0 (
start http://webpage
)
in revision.bat:
svnlook youngest D:\Subversion\...
Now i get this error in SVN:
post-commit hook failed (exit code 255) with output:
a" ) was unexpected at this time.
I believe it is because i create variable a
in a wrong place at wrong time. But I do not get this error if i run bat file manually
Found one way to do it - to store intermediate function in .bat file:
post-commit.bat
revision.bat
This is rather a workaround than a solution in my opinion
Thanks to: https://serverfault.com/questions/245679/store-output-of-windows-command-in-batch-file