win32pipe.popen3

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jakob Simon-Gaarde

    #1

    win32pipe.popen3

    Follow-up on a thread from 1999 (see below)

    Well now it is 2005 and the operating system I'm using is Windows
    Server 2003, and I can still see that the same problem persists with:

    win32pipe.popen 2()
    win32pipe.popen 3()
    win32pipe.popen 4()

    while win32pipe.popen () does almost what you want.
    [color=blue][color=green][color=darkred]
    >>> import win32pipe
    >>> win32pipe.popen ('cmd')[/color][/color][/color]
    <open file 'cmd', mode 'r' at 0x009DD698>[color=blue][color=green][color=darkred]
    >>> r=win32pipe.pop en('cmd')
    >>> r.readline()[/color][/color][/color]
    'Microsoft Windows XP [Version 5.1.2600]\n'[color=blue][color=green][color=darkred]
    >>> r.readline()[/color][/color][/color]
    '(C) Copyright 1985-2001 Microsoft Corp.\n'[color=blue][color=green][color=darkred]
    >>> r.readline()[/color][/color][/color]
    '\n'[color=blue][color=green][color=darkred]
    >>> r.readline()[/color][/color][/color]
    'C:\\backup\\TR Python241\\trpy thon>'

    Although I think the last readline ought to return None since no
    carriage return has been issued yet, it is better than popen2,popen3
    and popen4, which all just block the parent process.

    The current behaviour of win32pipe.popen 2(), win32pipe.popen 3() and
    win32pipe.popen 4() would be acceptable for me if I knew a way to test
    if there was something ready for reading, but I can't see how to do
    that test, therfore I don't know when to stop reading from output :( Is
    there a solution for this, can I poll/test for ready-read on popen3 I/O
    objects.

    Best regards
    Jakob Simon-Gaarde


    ---------------------------[color=blue]
    >From a thread in 1999[/color]
    High Arpard,

    thanx for help but I got probs with that popen3 under Win95:
    'o.readlines()' doesn't return anymore. To find out I checked
    it line per line:

    Python 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on win32
    Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam[color=blue][color=green][color=darkred]
    >>> import win32pipe
    >>> i,o,e=win32pipe .popen3('ver', 'b')
    >>> o.readline()[/color][/color][/color]
    '\015\012'[color=blue][color=green][color=darkred]
    >>> o.readline()[/color][/color][/color]

    'Windows 95. [Version 4.00.1111]\015\012'
    [color=blue][color=green][color=darkred]
    >>> o.readline()[/color][/color][/color]
    '\015\012'[color=blue][color=green][color=darkred]
    >>> o.readline()[/color][/color][/color]

    Don't know why, but it never;-) returns.
    Perhaps it may be a bug in win32pipe, that it doesn't return
    becourse readline couldn't find CarriageReturn/EOF?

    I took win32pipe.popen ('ver','r') for a better solution.
    That works fine.

    greetings,
    Holger

  • Jakob Simon-Gaarde

    #2
    Re: win32pipe.popen 3

    Me again.

    I forgot to mention that readline() in popen2,3 and 4 even locks up the
    parent-proces though it is called from a thread, so it's a real
    deadlock.

    Comment

    • Nicolas Fleury

      #3
      Re: win32pipe.popen 3

      Jakob Simon-Gaarde wrote:[color=blue]
      > Follow-up on a thread from 1999 (see below)
      >
      > Well now it is 2005 and the operating system I'm using is Windows
      > Server 2003, and I can still see that the same problem persists with:
      >
      > win32pipe.popen 2()
      > win32pipe.popen 3()
      > win32pipe.popen 4()
      >
      > while win32pipe.popen () does almost what you want.[/color]

      Have you tried subprocess?

      Regards,
      Nicolas

      Comment

      Working...