Controling the execution of external programs on Win2K 
Author Message
 Controling the execution of external programs on Win2K

Hi,

I placed a post last night looking for a way to run exe's from a python
programme, where the Python programme waits for each instance of the exe to
finish/return and exit code before proceding with it's next command.

As suggested I have looked at os.system( ) but on Win2K it seems every
external program I execute spawns an external command shell and there
doesn't seem a way to prevent this behaviour ... which is not good (atleast
from what I am trying to do) ...  after a bit more investigation I believe
it is possible to achieve this using the win32process module. I am just
unsure of what args to pass to make it behave in this way.

If anyone could provide further suggestions I would be most grateful :)

# Here is the piece of test code I have been toying with

import win32process

def CreateProcess(commandline):
                              sui = win32process.STARTUPINFO()
                              dummyvalue = win32process.CreateProcess(

None,

commandline,

None,

None,

0,

win32process.NORMAL_PRIORITY_CLASS,

None,

None,

sui)

# Spawns first executable ... python programme pauses until program1.exe
finishes running and closes

 CreateProcess("Programme1.exe /args")

# Once Programme1.exe returns an exit code ... the Python programme resumes
and Programme2 starts

 CreateProcess("Programme2.exe /args") #Once the instance of



Sun, 14 Sep 2003 13:14:00 GMT  
 Controling the execution of external programs on Win2K

Quote:

> Hi,

> I placed a post last night looking for a way to run exe's from a Python
> programme, where the Python programme waits for each instance of the exe to
> finish/return and exit code before proceding with it's next command.

> As suggested I have looked at os.system( ) but on Win2K it seems every
> external program I execute spawns an external command shell and there
> doesn't seem a way to prevent this behaviour ... which is not good (atleast
> from what I am trying to do) ...  after a bit more investigation I believe
> it is possible to achieve this using the win32process module. I am just
> unsure of what args to pass to make it behave in this way.

<snip>

You can't do that directly with the CreateProcess function.  If you
were using the Win32 API directly you would call WaitForSingleObject
or WaitForMultipleObjects, passing the process handle it returns.
In Python you could use something like this:

    def CreateProcess(commandline, wait):
        import win32event, win32process
        process, thread, pid, tid = win32process.CreateProcess(
            None,
            commandline,
            None,
            None,
            0,
            win32process.NORMAL_PRIORITY_CLASS,
            None,
            None,
            win32process.STARTUPINFO())
        if wait:
            win32event.WaitForSingleObject(process, win32event.INFINITE)

--
Any opinions expressed are my own and not necessarily those of Roundpoint.



Mon, 15 Sep 2003 06:46:33 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Execution of external programs from within Smalltalkenvironment

2. example of external program execution from zope

3. Controling other Program Controls

4. Advance Program: ILPS'91 Workshop on Parallel Execution of Logic Programs

5. sharing external functions between cms rexx programs and xedit rexx programs

6. multi-threaded *nix program needs to spawn an external program/script

7. Clipper program pauses when started running in Win2K Professional

8. Clipper dbase program problems with WIN2K

9. Win2k and specials program incompatibilities

10. QB/DOS programs for DAQ-700 under Win2K

11. launching a python program from GNU make (Win2K)

12. Background execution?, Parallel execution? in Labview

 

 
Powered by phpBB® Forum Software