Comunicate with external programs via popen

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • solarw
    New Member
    • Nov 2006
    • 3

    Comunicate with external programs via popen

    OS linux 2.6.18
    python 2.4.3

    i tried to compress data throw gzip using popen2.popen3

    Code:
    import  popen2
    a=popen2.Popen3("gzip -f")
    a.tochild.write("test data")
    a.tochild.flush()
    a.fromchild.read(5) #try to read 5 bytes from gzip
    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?
  • kudos
    Recognized Expert New Member
    • Jul 2006
    • 127

    #2
    Im just curious, are you able to send a EOF (Ctrl-D) to gzip before it returns?
    -kudos


    Originally posted by solarw
    OS linux 2.6.18
    python 2.4.3

    i tried to compress data throw gzip using popen2.popen3

    Code:
    import  popen2
    a=popen2.Popen3("gzip -f")
    a.tochild.write("test data")
    a.tochild.flush()
    a.fromchild.read(5) #try to read 5 bytes from gzip
    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?

    Comment

    • solarw
      New Member
      • Nov 2006
      • 3

      #3
      Originally posted by kudos
      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

      Comment

      • bartonc
        Recognized Expert Expert
        • Sep 2006
        • 6478

        #4
        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

        Comment

        • kudos
          Recognized Expert New Member
          • Jul 2006
          • 127

          #5
          Originally posted by solarw
          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

          Comment

          • solarw
            New Member
            • Nov 2006
            • 3

            #6
            Originally posted by kudos
            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

            Comment

            Working...