FAQ
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

Search Discussions

  • SuperHik at Jun 17, 2006 at 8:44 pm

    Dennis Lee Bieber wrote:
    On Sat, 17 Jun 2006 11:46:29 -0600, Jeffrey Barish
    <jeff_barish at earthlink.net> declaimed the following in comp.lang.python:
    I start. Is there a way to do this on Windows?
    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.aspx?scid=KB;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.
    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.*
    """
  • Reed at Jun 19, 2006 at 1:20 am

    Jeffrey Barish wrote:
    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
    import subprocess
    x = subprocess.Popen('nc -l 22222')
    x.pid
    2783
    subprocess.Popen('taskkill %s' % x.pid)
    <subprocess.Popen object at 0x0184D410>
    x.poll()
    1

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedJun 17, '06 at 5:46p
activeJun 19, '06 at 1:20a
posts3
users3
websitepython.org

3 users in discussion

Reed: 1 post SuperHik: 1 post Jeffrey Barish: 1 post

People

Translate

site design / logo © 2022 Grokbase