Terminating a subprocess '.exe'

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

    #1

    Terminating a subprocess '.exe'

    I launch a Windows executable and wish to close it from Python. The
    code is below. Normally, my program waits for rib.exe to finish, but
    I'd like to be able to close it from python if possible. (I suppose if
    I was going to do this, I wouldn't use .wait() ) Any ideas ?

    # Launch a program without launching a whole new cmd prompt
    def launchWithoutCo nsole(command, args):
    """Launches 'command' windowless and waits until finished"""
    startupinfo = subprocess.STAR TUPINFO()
    startupinfo.dwF lags |= subprocess.STAR TF_USESHOWWINDO W
    return subprocess.Pope n([command] + args,
    startupinfo=sta rtupinfo).wait( )

    ribHandle = launchWithoutCo nsole("rib.exe" ,["recovery"])

    # Is there a way to close "rib.exe" using ribHandle ?

  • Fredrik Lundh

    #2
    Re: Terminating a subprocess '.exe'

    "Ernesto" wrote:
    [color=blue]
    > I launch a Windows executable and wish to close it from Python. The
    > code is below. Normally, my program waits for rib.exe to finish, but
    > I'd like to be able to close it from python if possible. (I suppose if
    > I was going to do this, I wouldn't use .wait() ) Any ideas ?
    >
    > # Launch a program without launching a whole new cmd prompt
    > def launchWithoutCo nsole(command, args):
    > """Launches 'command' windowless and waits until finished"""
    > startupinfo = subprocess.STAR TUPINFO()
    > startupinfo.dwF lags |= subprocess.STAR TF_USESHOWWINDO W
    > return subprocess.Pope n([command] + args,
    > startupinfo=sta rtupinfo).wait( )
    >
    > ribHandle = launchWithoutCo nsole("rib.exe" ,["recovery"])
    >
    > # Is there a way to close "rib.exe" using ribHandle ?[/color]

    for 2.4 and earlier, see:



    for 2.5 (upcoming) and later, you can use either the ctypes method
    or the _subprocess.Ter minateProcess() call.

    </F>



    Comment

    • Ernesto

      #3
      Re: Terminating a subprocess '.exe'


      Fredrik Lundh wrote:[color=blue]
      > "Ernesto" wrote:
      >[color=green]
      > > I launch a Windows executable and wish to close it from Python. The
      > > code is below. Normally, my program waits for rib.exe to finish, but
      > > I'd like to be able to close it from python if possible. (I suppose if
      > > I was going to do this, I wouldn't use .wait() ) Any ideas ?
      > >
      > > # Launch a program without launching a whole new cmd prompt
      > > def launchWithoutCo nsole(command, args):
      > > """Launches 'command' windowless and waits until finished"""
      > > startupinfo = subprocess.STAR TUPINFO()
      > > startupinfo.dwF lags |= subprocess.STAR TF_USESHOWWINDO W
      > > return subprocess.Pope n([command] + args,
      > > startupinfo=sta rtupinfo).wait( )
      > >
      > > ribHandle = launchWithoutCo nsole("rib.exe" ,["recovery"])
      > >
      > > # Is there a way to close "rib.exe" using ribHandle ?[/color]
      >
      > for 2.4 and earlier, see:
      >
      > http://aspn.activestate.com/ASPN/Coo.../Recipe/347462
      >
      > for 2.5 (upcoming) and later, you can use either the ctypes method
      > or the _subprocess.Ter minateProcess() call.
      >
      > </F>[/color]

      Works EXACTLY the way I want it to. Thanks Fredrik !

      Comment

      Working...