stdout strangeness

Robert Bauck Hamar r.b.hamar at usit.uio.no
Wed Jul 8 07:59:41 CDT 2009


*Steve Borho:
>Can anyone explain this behavior?
>% echo "[hooks]\nprechangegroup.locked = echo REPOSITORY IS LOCKED &&
>exit 1" >> .hg/hgrc
[...]
>% hg push -v ../foo
>pushing to ../foo
>searching for changes
>1 changesets found
>running hook prechangegroup.locked: echo REPOSITORY IS LOCKED && exit 1
>REPOSITORY IS LOCKED
>abort: prechangegroup.locked hook exited with status 1
>
>This is exactly what you would expect.  Now if you run 'hgtk synch',
>enter the path, and press the 'push' button, you get this in the
>dialog:
>
>pushing to ../foo
>searching for changes
>1 changesets found
>running hook prechangegroup.locked: echo REPOSITORY IS LOCKED && exit 1
>abort: prechangegroup.locked hook exited with status 1
>
>Notice the hook output is missing.  If you look in your console
>window, you'll find the missing 'REPOSITORY IS LOCKED' message.

Let me take a guess: hgtk just replaces sys.std* to get output from hg, 
or something?

>The 
>thing is, the synchronize tool is doing everything I can think of to 
>get the output of these commands.  I'm subclassing ui and redirecting 
>write calls to my output window.  I'm redirecting sys.stdout and 
>sys.stderr to my output window, and I've even tested with redirecting 
>sys.__stdout__ and sys.__stderr__ to no effect.

The real solution must be to close the file descriptors, and reopen 
these to a pipe you can use. Something in the line of:

readfd, writefd = os.pipe()
os.dup2(writefd, sys.__stdout__.fileno())

The second line here will close the connection between sys.__stdout__ 
and the shell. That might be harmful. A better idea might be to 
monkeypatch os.system to use subprocess.Popen or something.

I'm not really sure how windows behaves, though.

-- 
Robert Bauck Hamar
USIT/SAPP/GT - Cerebrum
http://www.uio.no/sok?person=hamar
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://selenic.com/pipermail/mercurial/attachments/20090708/888a85cb/attachment.pgp 


More information about the Mercurial mailing list