Using os.popen3() to get binary data

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Christoph Krammer

    #1

    Using os.popen3() to get binary data

    Hello everybody,

    I need to get the different frames from a GIF image in my python
    script and want to use the giftopnm program from netpbm to get the
    frames and directly convert them to pnm files. I tried to use the
    following code:

    for image in images:
    if (image[0:3] == 'GIF'):
    (si, so, se) = os.popen3('gift opnm -image=all', 'b')
    si.write(image)
    frame = so.readlines()

    But with this code the script just hangs. When I interrupt the script,
    I get the following error message:
    Traceback (most recent call last):
    File "/home/tiger/stock-spam/scripts/all_in_one.py", line 46, in ?
    frames = so.readlines()
    KeyboardInterru pt
    close failed: [Errno 32] Broken pipe

    Can somebody tell me, which command I have to use that the pipe will
    be closed when the giftopnm returns? This program just prints the
    converted images to stdout and terminates.

    Thanks in advance,
    Christoph

  • =?ISO-8859-1?Q?Thomas_Kr=FCger?=

    #2
    Re: Using os.popen3() to get binary data

    Christoph Krammer schrieb:
    for image in images:
    if (image[0:3] == 'GIF'):
    (si, so, se) = os.popen3('gift opnm -image=all', 'b')
    si.write(image)
    frame = so.readlines()
    >
    But with this code the script just hangs. When I interrupt the script,
    I get the following error message:
    Traceback (most recent call last):
    File "/home/tiger/stock-spam/scripts/all_in_one.py", line 46, in ?
    frames = so.readlines()
    KeyboardInterru pt
    close failed: [Errno 32] Broken pipe
    Just a try: use read() instead of readlines()!

    Thomas

    Comment

    • Christoph Krammer

      #3
      Re: Using os.popen3() to get binary data

      Just got the solution...

      After sending the image data with "si.write(image )", I have to close
      the pipe to tell the program to convert the image with "si.close() ".
      Now everything works fine.

      Christoph


      Comment

      • MRAB

        #4
        Re: Using os.popen3() to get binary data

        On Apr 6, 6:09 pm, Dennis Lee Bieber <wlfr...@ix.net com.comwrote:
        On 6 Apr 2007 04:02:52 -0700, "Christoph Krammer"
        <redtige...@goo glemail.comdecl aimed the following in comp.lang.pytho n:
        >
        Hello everybody,
        >
        I need to get the different frames from a GIF image in my python
        script and want to use the giftopnm program from netpbm to get the
        frames and directly convert them to pnm files. I tried to use the
        following code:
        >
        for image in images:
        if (image[0:3] == 'GIF'):
        >
        What type of data /is/ "image" that the FIRST three characters
        identify the type? If it's the name of the file (I don't know what
        giftopnm requires for input) I'd have expected the last three to
        identify..
        >
        [snip]
        FYI, the first 3 bytes of a GIF image are the ASCII characters "GIF".

        Comment

        Working...