473,396 Members | 1,975 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

codecs / subprocess interaction: utf help requested

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.
Thanks,
Chris
---------------------------
#!/usr/bin/python
import subprocess

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

Jun 10 '07 #1
2 1835
On Jun 11, 7:17 am, smitty1e <smitt...@gmail.comwrote:
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,
Whatever gave you that idea?
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.
Get your head out of the red herring factory; unicode, "utf" (which
one?) and codecs have nothing to do with your problem. Think about
looking at your own code and at the bzip2 documentation.
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.
Thanks,
Chris
---------------------------
#!/usr/bin/python
import subprocess

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

p0 = subprocess.Popen(["cat","/usr/share/man/man1/mktemp.1.bz2"],
stdout=subprocess.PIPE)
p1 = subprocess.Popen(["bzip2"], stdin=p0.stdout ,
stdout=subprocess.PIPE)
stdout, stderr = p1.communicate()
print stdout
---------------------------
You left out the command-line options for bzip2. The "rat" that you
saw was the result of compressing the already-compressed man page.
Read this:
http://www.bzip.org/docs.html
which is a bit obscure. The --help output from my copy of an antique
(2001, v1.02) bzip2 Windows port explains it plainly:
"""
If invoked as `bzip2', default action is to compress.
as `bunzip2', default action is to decompress.
as `bzcat', default action is to decompress to stdout.

If no file names are given, bzip2 compresses or decompresses
from standard input to standard output.
"""

HTH,
John

Jun 10 '07 #2
On Jun 10, 6:10 pm, John Machin <sjmac...@lexicon.netwrote:
On Jun 11, 7:17 am, smitty1e <smitt...@gmail.comwrote:
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,

Whatever gave you that idea?
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.

Get your head out of the red herring factory; unicode, "utf" (which
one?) and codecs have nothing to do with your problem. Think about
looking at your own code and at the bzip2 documentation.
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.
Thanks,
Chris
---------------------------
#!/usr/bin/python
import subprocess
p = subprocess.Popen(["bzip2", "-c", "-d", "/usr/share/man/man1/mktemp.
1.bz2"]
, stdout=subprocess.PIPE)
stdout, stderr = p.communicate()
print stdout
p0 = subprocess.Popen(["cat","/usr/share/man/man1/mktemp.1.bz2"],
stdout=subprocess.PIPE)
p1 = subprocess.Popen(["bzip2"], stdin=p0.stdout ,
stdout=subprocess.PIPE)
stdout, stderr = p1.communicate()
print stdout
---------------------------

You left out the command-line options for bzip2. The "rat" that you
saw was the result of compressing the already-compressed man page.
Read this:http://www.bzip.org/docs.html
which is a bit obscure. The --help output from my copy of an antique
(2001, v1.02) bzip2 Windows port explains it plainly:
"""
If invoked as `bzip2', default action is to compress.
as `bunzip2', default action is to decompress.
as `bzcat', default action is to decompress to stdout.

If no file names are given, bzip2 compresses or decompresses
from standard input to standard output.
"""

HTH,
John
Don't I feel like the biggest dork on the planet.
I had started with
>cat /usr/share/man/man1/paludis.1.bz2 | bunzip2
then proceeded right to a self-foot-shoot when I went to python.
*sigh*
Thanks for the calibration, sir.
Rm
C

Jun 10 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: py.adriano | last post by:
Hi folks, I'm trying to use the nmap runtime interaction feature while using it with the subprocess module. For those not familiar with nmap, the runtime interaction feature allow users to get...
7
by: Dave Sampson | last post by:
hey folks, A simple question hopefully. despite all my searching I have not found a satisfactory response. The goal. Interact with a command line program. Simple enough, but the key is...
1
by: | last post by:
Hello all I want to convert a tex file into a pdf by using pdflatex. For that, I thought the 'subprocess' module might be a good option. My code doesn't work atall tho: Import os, subprocess ...
0
by: Christian Heimes | last post by:
Dominique.Holzwarth@ch.delarue.com schrieb: The pdflatex job stales when the standard stream buffers are full. Why do you need stdin anyway? The community method should do the trick for you: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.