Launch windows batch file from wxPython (2 requirements)

If you are running win32-only you might as well use win32api. That way you can do pretty much whatever you want.

For reference, attached is parts of some code I used a while ago.

from __future__ import nested_scopes
import win32process
import win32event
import win32api
import win32con
import win32pdhutil

class ProcessUtil:

    def create(self, cmd, rect=None):
        si = win32process.STARTUPINFO()
        if rect == None:
            # No position given. Place in upper right corner, use 1/4 of screen size
            si.dwX = 0
            si.dwY = 0
            si.dwX = win32api.GetSystemMetrics(win32con.SM_CXSCREEN) / 2
            si.dwY = win32api.GetSystemMetrics(win32con.SM_CYSCREEN) / 2
        else:
            si.dwX, si.dwY, si.dwXSize, si.dwYSize = rect
        si.dwFlags = win32process.STARTF_USEPOSITION | win32process.STARTF_USESIZE
        self.pinfo = win32process.CreateProcess(None, cmd, None, None, 0, win32process.NORMAL_PRIORITY_CLASS, None, None, si)
        self.handle = self.pinfo[0]
        self.created = 1

    def createAndWait(self, cmd, timeOut=-1):
        self.create(cmd)
        self.waitForProcess(timeOut)

   def waitForProcess(self, timeout=-1):
        "Wait for a process to terminate. If process is not terminated within given time, terminate it"

        if self.created:
            rc = win32event.WaitForSingleObject(self.handle, timeout)
            if rc != win32event.WAIT_OBJECT_0:
                self.terminate()
            #self.running = 0
        else:
            rc = win32event.WaitForSingleObject(self.handle, timeout)
            if rc != win32event.WAIT_OBJECT_0:
                print "Process timed out"

    def terminate(self):
        "Terminate running process"

        if self.created:
            rc = win32process.TerminateProcess(self.handle, 0)
            self.created = 0

···

-----Original Message-----
From: Jens.Bloch.Helmers@dnv.com [mailto:Jens.Bloch.Helmers@dnv.com]
Sent: den 12 mars 2003 10:15
To: wxPython-users@lists.wxwindows.org
Subject: [wxPython-users] Launch windows batch file from wxPython (2
requirements)

I want the following to happen when I launch a windows bat file from
wxPython:
1) No "dos-window" should appear on the screen.
2) My GUI should wait until the bat file finish.

So far I'm only able to satisfy 1 of the requirements:

os.system('my.bat > nul')
os.spawnv( os.P_WAIT, 'my.bat', ('my.bat',' > nul') )
dump = os.popen( 'my.bat' )

The first two waits for the process to finish, but display the anoying
dos-window.
The last one does not display the dos-window but don't wait for the bat file
to complete.

Is there a third option? Can Python/wxPython handle both requirements at the
same time?

Thanks for any help!
Jens

**********************************************************************
Neither the confidentiality nor the integrity of this message
can be guaranteed following transmission on the Internet.
This message has been swept by MAILsweeper at DNV for
the presence of computer viruses.
**********************************************************************