Trying to use cscope via pipes

Paul Walker arafel at gmail.com
Mon Jul 12 16:21:38 CEST 2004


Hi all,

I'm currently trying to put together a small script to talk to cscope
(http://cscope.sf.net/) via pipes. The obvious way to do this is via
popen2 (or popen4).

I've tried both the one in the os module and the one in the popen2
module, and I get the same effect with both - I don't get any response
on the stdout pipe until I've closed the stdin pipe, even if I call
flush().

What I'm trying to do should be possible, I think - cscope says that
it supports a line-oriented interface for this kind of thing, and the
cbrowser tool (written in tcl) uses cscope as a backend via pipes. So
the conclusion is that I'm missing something, but I can't quite work
out what... any ideas?

Script:

==
from os import popen2

handles = popen2("cscope -d -l")
writer = handles[0]
reader = handles[1]

writer.writelines("2bigphysarea_alloc_pages\n")
writer.flush()
#without closing it'll just hang... strange.
#writer.close()
lines = reader.readlines()
print lines
==

I'm using the following Python, since there aren't Python 2.3 RPMs
until Fedora C2 (and this is a work machine which I shouldn't update
too much):

Python 2.2.2 (#1, Feb 24 2003, 19:13:11)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-4)] on linux2

Thanks,

Paul



More information about the Python-list mailing list