portable way to tell what Popen will call

B

Brendan Miller

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?

Thanks,
Brendan
 
G

Gabriel Genellina

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.
 
V

Ville M. Vainio

Brendan Miller said:
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

Actually, if you pass the use_shell = 1 argument to Popen, it will
launch the process using a shell - that is, what you expect to work in
a shell (and consequently os.system()) will work.
to check what Popen will work on without actually execute it? Do I
have to write a bunch of platform specific code here?

Unfortunately, you'll probably need to write platform specific kludges
for this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,265
Latest member
TodLarocca

Latest Threads

Top