codecs / subprocess interaction: utf help requested

smitty1e smitty1e at
Sun Jun 10 23:17:40 CEST 2007

The first print statement does what you'd expect.
The second print statement has rather a lot of rat in it.
The goal here is to write a function that will return the man page for
some command (mktemp used as a short example here) as text to client
code, where the groff markup will be chopped to extract all of the
command options.  Those options will eventually be used within an
emacs mode, all things going swimmingly.
I don't know what's going on with the piping in the second version.
It looks like the output of p0 gets converted to unicode at some
point, but I might be misunderstanding what's going on.  The 4.8
codecs  module documentation doesn't really offer much enlightment,
nor google.  About the only other place I can think to look would be
the unit test cases shipped with python.
Sort of hoping one of the guru-level pythonistas can point to
illumination, or write something to help out the next chap.  This
might be one of those catalytic questions, the answer to which tackles
five other questions you didn't really know you had.
import subprocess

p = subprocess.Popen(["bzip2", "-c", "-d", "/usr/share/man/man1/mktemp.
                    , stdout=subprocess.PIPE)
stdout, stderr = p.communicate()
print stdout

p0 = subprocess.Popen(["cat","/usr/share/man/man1/mktemp.1.bz2"],
p1 = subprocess.Popen(["bzip2"], stdin=p0.stdout                ,
stdout, stderr = p1.communicate()
print stdout

More information about the Python-list mailing list