portable way to tell what Popen will call

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed May 14 03:26:30 EDT 2008


En Tue, 13 May 2008 23:14:56 -0300, Brendan Miller <catphive at catphive.net>  
escribió:

> I need a portable way to tell what subprocess.Popen will call.
>
> For instance on unix systems, Popen will work for files flagged with the
> executable bit, whereas on windows Popen will work on files ending the in
> .exe extension (and I don't think anything else). Is there a portable way
> to check what Popen will work on without actually execute it? Do I have  
> to
> write a bunch of platform specific code here?

On Windows, for a quick and dirty answer, include: *.exe,*.cmd,*.bat,*.com

 From the documentation of CreateProcess (Windows), used internally by  
subprocess:
<http://msdn.microsoft.com/en-us/library/ms682425(VS.85).aspx>
Apart from .exe files (PE) - DOS programs (.com and .exe) and 16 bits  
Windows executables (NE) are valid if the appropriate subsystem is enabled.
.bat and .cmd scripts are supported too, altough this isn't explicitely  
menctioned in the docs.
The different executable formats are identified by signature, not  
extension. You can rename foo.exe as foo.xxx and it will be valid still.  
Only for .exe, you can leave out the extension (but CreateProcess does  
*not* use the PATHEXT environment variable; you can't leave out the .cmd  
extension by example).

Even if you filter out things, you have to handle exceptions in Popen. A  
jpeg image with the executable bit set won't be accepted on Unix-like  
systems.

-- 
Gabriel Genellina




More information about the Python-list mailing list