Popen3 on Windows

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeffrey Barish

    #1

    Popen3 on Windows

    I have an application that has been working fine on Linux, but now I need to
    port it to Windows XP. The program uses Popen3 to run another program. I
    use Popen3 so that I can access the pid attribute, which I use to kill the
    auxiliary program when necessary. Popen3 does not exist on Windows. I see
    os.popen2 and os.popen3, but they provide only file objects for stdin,
    stdout, and stderr so I don't see a way to kill the auxiliary program that
    I start. Is there a way to do this on Windows?
    --
    Jeffrey Barish

  • SuperHik

    #2
    Re: Popen3 on Windows

    Dennis Lee Bieber wrote:[color=blue]
    > On Sat, 17 Jun 2006 11:46:29 -0600, Jeffrey Barish
    > <jeff_barish@ea rthlink.net> declaimed the following in comp.lang.pytho n:
    >[color=green]
    >> I start. Is there a way to do this on Windows?[/color]
    >
    > There is no safe, easy, way to reliably kill a program on Windows...
    >
    > Hmmm, there's one I hadn't know about...
    > http://www.tech-recipes.com/windows_tips446.html
    > Ah, not supplied in WinXP Home (my desktop is Pro)
    >
    > Seems besides taskkill, there is also a tskill with different
    > arguments...
    >
    > The M$ response
    > http://support.microsoft.com/default...;en-us;178893&
    >
    >
    > Granted, these don't explain how to get the PID in the first place
    > from Python.
    >
    > If possible, try using the subprocess module... It seems to have a
    > PID attribute.
    >[/color]
    from http://docs.python.org/dev/lib/module-subprocess.html
    """
    16.1 subprocess -- Subprocess management

    New in version 2.4.

    The subprocess module allows you to spawn new processes, connect to
    their input/output/error pipes, and obtain their return codes. This
    module *intends to replace* several other, older modules and functions,
    such as:

    os.system
    os.spawn*
    os.popen*
    popen2.*
    commands.*
    """

    Comment

    • reed

      #3
      Re: Popen3 on Windows


      Jeffrey Barish wrote:[color=blue]
      > I have an application that has been working fine on Linux, but now I need to
      > port it to Windows XP. The program uses Popen3 to run another program. I
      > use Popen3 so that I can access the pid attribute, which I use to kill the
      > auxiliary program when necessary. Popen3 does not exist on Windows. I see
      > os.popen2 and os.popen3, but they provide only file objects for stdin,
      > stdout, and stderr so I don't see a way to kill the auxiliary program that
      > I start. Is there a way to do this on Windows?
      > --
      > Jeffrey Barish[/color]
      [color=blue][color=green][color=darkred]
      >>>import subprocess
      >>>x = subprocess.Pope n('nc -l 22222')
      >>>x.pid[/color][/color][/color]
      2783[color=blue][color=green][color=darkred]
      >>>subprocess.P open('taskkill %s' % x.pid)[/color][/color][/color]
      <subprocess.Pop en object at 0x0184D410>[color=blue][color=green][color=darkred]
      >>> x.poll()[/color][/color][/color]
      1

      Comment

      Working...