Need a cross-platform way to execute binary

Gabriel Genellina gagsl-py at yahoo.com.ar
Sat Feb 10 19:22:52 EST 2007


En Sat, 10 Feb 2007 08:48:31 -0300, techtonik <techtonik at gmail.com>  
escribió:

> On Feb 10, 12:03 pm, "Gabriel Genellina" <gagsl... at yahoo.com.ar>

>> > Here "executable" means file that
>> > could be be launched by system() (if there are any other ways - I'd be
>> > happy to know them)

This is a very specific definition of "executable". os.access does not use  
that definition.

>> >>>> os.access("../../ufo2map", os.X_OK)
>> > False
>>
>> That's right - such file does not exist. On Windows, in general, X_OK is
>> the same as F_OK: for any existing file, whatever name or extension,
>> returns True. Permissions are managed thru ACL and this simple function
>> does NOT consider them.
>
> It shouldn't matter if the file exists or not. Quoting http://
> docs.python.org/lib/os-file-dir.html:
> "
> X_OK
>      Value to include in the mode parameter of access() to determine
> if path can be executed.
> "
>
> See - there is no "file" notation as only "path" is tested and "path"
> is pretty executable.

It appears that your argument is: os.system("../../ufo2map") launches a  
new process, so "../../ufo2map" must be executable. But  
os.system("foo.txt") also works, so "foo.txt" is also executable?
Please define "executable" first. The definition may be so restrictive as  
to only include PE files (all others require a wrapping process) or so  
broad as to include almost anything known to the system.

> I think this should be clarified in os.access()
> documentation to make the whole business less confusing if not
> implemented in interpreter itself. After all the purpose of cross-
> platform language is to free developer from writing platform-specific
> code.

os.access documentation is rather clear - it's just a wrapper around the  
access() system call, and I think it should not be changed. It is the  
underlying OS which gives the answer, not Python.

On the other hand, an utility library exposing FindExecutable,  
ShellExecute, associations and other shell goodies might be useful. Maybe  
you could do some research, whether such thing exists, and help improve it  
or design a good interfase?

> I would prefer to know as little about underlying platforms as
> possible.
> It would only be a big plus for Python.

Sure, but someone has to write it. I can't think of a good abstraction  
right now, perhaps you have some ideas?

-- 
Gabriel Genellina




More information about the Python-list mailing list