473,509 Members | 2,828 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Comunicate with external programs via popen

3 New Member
OS linux 2.6.18
python 2.4.3

i tried to compress data throw gzip using popen2.popen3

Expand|Select|Wrap|Line Numbers
  1. import  popen2
  2. a=popen2.Popen3("gzip -f")
  3. a.tochild.write("test data")
  4. a.tochild.flush()
  5. a.fromchild.read(5) #try to read 5 bytes from gzip
  6.  
but can't recive thouse 5 bytes, program hangs on read
cat /filename |gzip -f>filename2 - works excelent
don't offer to use zlib or bz2 modules
i wish to compress long data sequens throw external program so sending EOF is not good decition

how to write data to external program and recive result immidiatly?
Nov 1 '06 #1
5 2277
kudos
127 Recognized Expert New Member
Im just curious, are you able to send a EOF (Ctrl-D) to gzip before it returns?
-kudos


OS linux 2.6.18
python 2.4.3

i tried to compress data throw gzip using popen2.popen3

Expand|Select|Wrap|Line Numbers
  1. import  popen2
  2. a=popen2.Popen3("gzip -f")
  3. a.tochild.write("test data")
  4. a.tochild.flush()
  5. a.fromchild.read(5) #try to read 5 bytes from gzip
  6.  
but can't recive thouse 5 bytes, program hangs on read
cat /filename |gzip -f>filename2 - works excelent
don't offer to use zlib or bz2 modules
i wish to compress long data sequens throw external program so sending EOF is not good decition

how to write data to external program and recive result immidiatly?
Nov 1 '06 #2
solarw
3 New Member
Im just curious, are you able to send a EOF (Ctrl-D) to gzip before it returns?
-kudos

i need to proceed data strem so if i send EOF stream will be interupted
Nov 2 '06 #3
bartonc
6,596 Recognized Expert Expert
I'm on Windows, so can't be of much help. But reading the docs, your usage of the class appears to be a bit off:

popen3( cmd[, bufsize[, mode]])
Executes cmd as a sub-process. Returns the file objects (child_stdout, child_stdin, child_stderr).
On Unix, a class defining the objects returned by the factory functions is also available.

class Popen3( cmd[, capturestderr[, bufsize]])
This class represents a child process.

Normally, Popen3 instances are created using the popen2() and popen3() factory functions described above.

6.9.2 address flow issues. I hope this is of some use,
Barton
Nov 2 '06 #4
kudos
127 Recognized Expert New Member
i need to proceed data strem so if i send EOF stream will be interupted
yes I know, but are you able to send something to the gzip program at all? I thought that the program had to return before python could manipulate it (correct me if I am wrong here )

By the way, why not just use zlib modules that comes with python? I think there even is a gzip module too (If I remeber correctly the zlib and gzip are equal apart from the header format).

-kudos
Nov 2 '06 #5
solarw
3 New Member
yes I know, but are you able to send something to the gzip program at all? I thought that the program had to return before python could manipulate it (correct me if I am wrong here )

By the way, why not just use zlib modules that comes with python? I think there even is a gzip module too (If I remeber correctly the zlib and gzip are equal apart from the header format).

-kudos

i wish to compress data stream by lzma program
pylzma is not ready for this, so i decide to use external lzma program
problem with lzma is like problem with gzip
Nov 2 '06 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
3528
by: Fernando Rodriguez | last post by:
Hi, How can I save the output of an external program, called with os.system()?
2
1649
by: PWR | last post by:
Platform: Windows Python: 2.3 Python Skill: Reading, Learning, but still newbie. Mission: My mission is writing a script that is triggered from my mail server. The script will execute and...
10
8221
by: Sanyi Benczik | last post by:
Is there a standard way in C++ to call an external program or is this platform dependent? If it is platform dependent, can somebody drop a line what to use or where to look for info for GNU C++...
8
1509
by: Hagar | last post by:
I am currently learning C++ and am into a project for the end of the semester finals. Everything is rosy except for one feature that I want to include and can't find in my very large and...
0
1368
by: jfigueiras | last post by:
>I have a problem with the module subprocess! As many other programs... I'm not sure what you mean by "non-standard file descriptors". The other program is free to open, read, write, etc any...
2
1964
by: Murali | last post by:
Hi Python programmers, I need to be able to read the stdout and stderr streams of an external program that I launch from my python script. os.system( 'my_prog' + '>& err.log' ) and was planning...
1
1493
by: Emerald Saint | last post by:
Hi. I been away and didn't get here again until now. Thank you for your offer to share programs that you have. I studied up and refreshed my memory about linkers and compilers. So I have the...
11
5042
by: Emmanouil Angelakis | last post by:
Hi, I am tryiong to do something obviously trivial such as: I have a c program called "tsys2list" that when it is ran it asks the user to give the value of "tcal" which is a variable. I want to...
3
4710
by: ckkart | last post by:
Hi, on XP when starting a certain external program (plain C calculation program which communicates via stdout/fs) from python 2.5 using subprocess.Popen the external program crashes. It does not...
0
7237
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
7137
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7347
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
7416
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...
1
7073
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
7506
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...
1
5062
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3207
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
779
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.