473,669 Members | 2,458 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 2281
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
3531
by: Fernando Rodriguez | last post by:
Hi, How can I save the output of an external program, called with os.system()?
2
1659
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 download a file. The email that triggered the message has a file size which is compared to the downloaded file to make sure the bytes match. Once that is accomplished there is a small program (.exe) that I can run against the file. The ..exe has...
10
8252
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++ on RedHat? I am doing some numerical calculations and need to invoke an external plotting program (gnuplot) and return to the numerics. Sorry if I posted twice.
8
1518
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 expensive C++ books. Plus, I don't want to ask the instructor because that will give my project away. How do you call an external non C++ program, or possibly a system function? For instance, I have some very good Perl modules from my last class that...
0
1376
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 file he wants - are you trying to trap any file operation it may want to do? You *could* do such things -google for "code injection" and "API hooking"- but I doubt it's what you really want.
2
1969
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 on monitoring err.log and to display its contents. Is this the best way to do this? Thanks, Murali.
1
1500
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 answer to the question I asked here. I found a Microsoft site where they have 'Express' editions for VisualC++ and Visual Basic and other stuff. It is all free. I downloaded the VC++ Express edition and discovered there are ways to use it for...
11
5062
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 call the "tsys2list" from within a pyrthon script lets call it "gamma.py" >>>but<<< I want to pass the value of "tcal" to th eprogram automatically and not by interacting with the keyboard. How do I do that? thanks i advance! manolis
3
4727
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 if started directly from the XP command prompt. This is not a purely python problems since the crash occurs as well if started e.g. from a msys bash shell. The only things I find worth mentioning from the windows debugging message is that...
0
8465
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8895
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8658
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6210
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4386
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2797
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2032
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.