I'm trying pre-revprop-change hook script on a Windows machine, but find a tough problem.
I distill my problem to the following scenario:
I have C:\csvn\data\repositories\tr1\hooks\pre-revprop-change.bat with content:
D:\svntest\testhook.py %*
exit %ERRORLEVEL%
testhook.py is:
import os, sys
if __name__ == '__main__':
# sys.stderr.write(sys.version+'\n') # this is OK, tried.
newtext = sys.stdin.read() # try to read new log message
sys.stderr.write('newtext is: %s\n'%newtext)
exit(2)
However, when doing a client-side svn propset svn:log --revprop -r 2 "newtext"
, I got python error:
Traceback (most recent call last):
File "D:\svntest\testhook.py", line 5, in <module>
newtext = sys.stdin.read() # try to read new log message
IOError: [Errno 9] Bad file descriptor
What's the cause of this error?
It seems that pre-revprop-change.bat does not pass STDIN handle to the py script. Yes, I verified that pre-revprop-change.bat can fetch text from STDIN(according to instructions in Read stdin stream in a batch file).
I also tried to run pre-revprop-change.bat directly from command line, sys.stdin.read()
is OK.
Please kindly help me out.
Screen shot below:
Env:
- Windows Server 2003
- Collabnet Subversion Edge 2.3(svn 1.7.3 and Apache 2.2.22)
- Install Python 2.7.1 msi from python.org
===============[LATEST UPDATE]======================
I'm sorry to say: I should have written in the .bat
exit %ERRORLEVEL%
instead of
exit /b %ERRORLEVEL%
For someone who have tried it with me, please fix it and try again. The /b
seems to have pre-revprop-change.bat always exit with 0. TIP: Without /b
, running the .bat directly from a cmd window will cause the cmd window to close, so we'd better try it with cmd /c "pre-revprop-change.bat some param"
.
Quick way to reproduce this problem below
What's more, for those who is still interested, please
- download this file package http://down.nlscan.com/misc/chjsvnpyhook.zip ,
- extract them to D:\ ,
- cd into D:\svntest\tr1_local ,
- run elog.bat (
svn propset svn:log --revprop -r 2 "newtext"
)
then my problem will be reproduced. (Requirement: svn.exe 1.7 command line(whether collabnet or TortoiseSVN), and Python 2.7 installed)
If you still cannot reproduce the error. I've prepared a VMware virtual machine that exhibits the problem exactly. Download the VM at http://down.nlscan.com/misc/chj/winxp-svnhook-py-stdin-error.7z (link expected to be valid until Sep 2013). VMware Player 3.0(free) is sufficient to run that VM.
===============[WORKAROUND FOUND]===================
Very nice workaround provided by @nmenezes, with c:\Python27\python.exe D:\svntest\testhook.py %*
in bat .