Wrapping an SVN Python hook in a Windows batch file

1.4k views Asked by At

I have an SVN pre-commit hook that previously resided on a Linux server. I'm now trying to move things over to a Windows (Server 2003) server.

This hook was written in Python, which worked fine on Linux with its #!/usr/bin/env python line at the top. Windows, however, doesn't work that way and requires hooks to be batch files (or other formats, but still not Python).

The important thing is that the arguments get passed to the script and the exit code gets returned to the calling process (the SVN server), so that it knows whether or not to allow the commit. I know next to nothing about .bat file syntax, but I thought that something like this would do the trick:

C:\Python26\python.exe pre-commit.py %1 %2

Am I right in thinking that this is the simplest way to wrap the Python script? Will it automatically return the exit code of the script?

1

There are 1 answers

2
detly On BEST ANSWER

To answer my own question: this almost works. The exit code is detected through the ERRORLEVEL variable, but due to the empty environment, the path to the script must be fully specified. Thankfully the first argument contains the location of the repository, so it's just:

C:\Python26\python.exe %1\hooks\pre-commit.py %1 %2