开发者

SVN Error When Accessed Through Python

开发者 https://www.devze.com 2023-01-25 16:32 出处:网络
I have Python 3.1, Subversion 1.6.12, and PySVN installed on Windows XP. If I open a Python terminal and do

I have Python 3.1, Subversion 1.6.12, and PySVN installed on Windows XP.

If I open a Python terminal and do

import subprocess
print subprocess.check_output(['svnlook','youngest','D:/svn-repos/myrepo'])

I get the expected revision number.

However, if I add this to Subversion's post-commit.bat, it fails with the error "The handle is invalid":

  File "C:\Program Files\Python31\lib\subprocess.py", line 472, in check_output
    process = Popen(*popenargs, stdout=PIPE, **kwargs)
  File "C:\Program Files\Python31\lib\subprocess.py", line 651, in __init__
    errread, errwrite) = self._get_handles(stdin, stdout, stderr)
  File "C:\Program Files\Python31\lib\subprocess.py", line 750, in _get_handles
    p2cread = GetStdHandle(STD_INPUT_HANDLE)
WindowsError: [Error 6] The handle is invalid

What could be causing this, and how would I fix it? I tried changing the Subversion service to run as my user, thinking it was some sort of permissions issue with the default systems account, but that had no effect.

Assuming there's no direct fix for this, how would I work around this? I need some way to retrieve the youngest revision number from a SVN repository without have a local working copy. I've dug through PySVN's Programmer's Reference, but I can't find the equivalent call to "svnlook youngest".

开发者_开发百科

Edit: I'm calling the script from the post-commit.bat like:

@ECHO OFF
"C:\Program Files\Python31\python.exe" "D:\svn-repos\myrepo\hooks\myscript.py"


I ended up using a different SVN binding, svn-python, and that worked. I can only guess there was some mismatch between the Windows binaries for the version of subversion and PySVN.


i think you don't need to use the subprocess (just for this) , you see you can just use :

import os

stdout = os.popen('svnlook youngest D:/svn-repos/myrepo')

print stdout.read()

Occam's razor :)

Because as i see it from here .bat file are old stuff, and subprocess that deal with a lot of redirection , processing i don't think this will work , but maybe i'm mistaken , maybe i just want to found you an excuse, but well ...

By the way, in the python script you do a print and you have @ECHO OFF in your .bat so i don't think it will work maybe you can wrap your command with something like this:

@ECHO ON
"C:\Program Files\Python31\python.exe" "D:\svn-repos\myrepo\hooks\myscript.py"
@ECHO OFF

well good luck :)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号