[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: Hooks and Perl on Windows

From: Dominic Anello <danello_at_danky.com>
Date: 2004-11-23 18:51:07 CET

On 2004-11-23 08:05:10 +0000, Jason Butlin wrote:
>
>
> >From: Toby Johnson <toby@etjohnson.us>
> >Reply-To: users@subversion.tigris.org
> >To: Jason Butlin <roguejay@hotmail.com>
> >CC: users@subversion.tigris.org
> >Subject: Re: Hooks and Perl on Windows
> >Date: Mon, 22 Nov 2004 14:35:04 -0500
> >
> >Jason Butlin wrote:
> >
> >>If I run the hook batch file from the command line (with the necessary
> >>tweaks to get it working), when the Perl script returns the DOS
> >>ERRORLEVEL variable is correctly set to 1 or 0, depending upon the exit
> >>call of the Perl script. However, when the batch file is run from SVN,
> >>the errorlevel code is always 0.
> >>
> >>Anyone got any ideas as to why this is?
> >
> >The problem is that even though your perl script is exiting with a
> >non-zero status, the batch script will always exit with a zero status
> >unless a problem occurs in the batch file.
> >
> >A way to trick it into sending a non-zero return status is to put the
> >following after you call your perl script:
> > if NOT %errorlevel% == 0 goto script_failed 2>nul
> >
> >However, *do not define* a "script_failed" label. This will cause your
> >batch file to attempt to go to a non-existant level, at which point the
> >batch file itself will error out. The "2>nul" prevents the error message
> >from the missing label from going to STDERR.
> >
> >You may be tempted to put "exit 1" instead of using this trick, but don't
> >do that: calling a batch file with "exit" in it will behave as though you
> >called "exit" from the command prompt, and shut down your session! Ah, the
> >hilarity never stops with Windows.
>
> Interesting point about not calling exit, which is what I do - and seems to
> work O.K. I might change it anyway.
>
> My problem lies in the fact that after calling the Perl scrip %errorlevel%
> will ALWAYS be equal to 0, no matter what the Perl script exits with. But
> if I run the batch file from the command line, the after the Perl script
> the errorlevel is correctly 0 or 1.
>
> Jay

How exactly are you invoking your script? The following worked for me
using ActiveState perl 4.6.1. I was running under apache, not
SVNServer, I don't know if that makes a difference.

The following worked for me... the two main things I do that might be
different from what you are doing is that I save the ERRORLEVEL
immediately after executing Perl. I also added the /B switch to exit,
which sets ERRORLEVEL and exits the batch instead of terminating the
process.

@echo off
set repo=%1
set txn=%2
set log=%repo%\log\pre-commit.log

( echo
========================================================================
echo Check commit on %repo% txn: %txn% ) >> %log%

D:\Perl\bin\perl.exe -w "%repo%\hooks\pre-commit-check.pl" "%repo%" "%txn%" 1>>%log%

set err=%errorlevel%

echo Commit status: %err% >> %log%

exit /B %err%

  • application/pgp-signature attachment: stored
Received on Tue Nov 23 18:50:40 2004

This is an archived mail posted to the Subversion Users mailing list.