views:

39

answers:

2

I'm looking for a Python function which behaves just like the Windows command interpreter cmd.exe when it comes to waiting for newly launched processes to finish. Right now I'm using os.system() but this function always blocks, even when launching GUI applications (which, in case they were written in C/C++, have a WinMain function and were linked with /SUBSYSTEM:WINDOWS).

What code should I be using for launching external processes in case I do want the function to block when launching console applications, but I do not want it to block when launching GUI applications?

A: 

Python has no standard way to examine the executables you can start with the process API.

How about you start the external command using cmd.exe? Or create a BAT script in %TEMP% and run that.

Aaron Digulla
Launching an external process via `cmd /C` doesn't seem to be the same. For instance, running `notepad` directly returns to the prompt immediately. Running `cmd /C notepad` waits until notepad finished before returning.
Frerich Raabe
Isn't DOS fun? Well, in that case you'll need to teach Python what the command will do after starting it, so it can execute it with `cmd /C start/b` to run it in the background without waiting.
Aaron Digulla
+2  A: 

You could write a small C wrapper/extension that checks for the subsystem (using ImageNtHeader). If all else fails, you can parse the PE headers directly.

Philipp
start isn't a program (in an executable file). It's a command in the command interpreter.
wj32
OK, thanks, deleted.
Philipp
+1: This is unfortunately the only solution I see so far. :-/
Frerich Raabe
Actually, it shouldn't be extremely hard to write a simple extension if you can use something like Boost.Python.
Philipp