473,761 Members | 2,410 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need a cross-platform way to execute binary

Hello, everyb.

Does anybody know simple cross-platform method of probing if
executable binary is available and launching it.
Problem no.1: test if executable file is available
I'll take windows platform as the most relevant in this case.
os.access() doesn't handle env PATHEXT and can't detect if a given
path would be executable or not. Here "executable " means file that
could be be launched by system() (if there are any other ways - I'd be
happy to know them)

Suppose I have "ufo2exe" executable two directories up.
>>os.access(" ../../ufo2map.exe", os.X_OK)
True

However...
>>os.access(" ../../ufo2map", os.X_OK)
False

But...
>>os.system(".. \..\ufo2map")
---- ufo2map 1.0 ----
0
Problem no.2: launch executable file
The same windows platform again. All python commands are using forward
slashes for paths, but system doesn't handle this situation (it could
at least try to convert immediate forward slashes to backwards)

os.access() thinks this file is executable, but os.system() fails ...
>>os.access(" ../../ufo2map.exe", os.X_OK)
True
>>os.system(" ../../ufo2map.exe")
'..' is not recognized as an internal or external command,
operable program or batch file.
1

the contrary - access() fails to tell this path can be launched, but
file Is executable, ...
>>os.access(".. \..\ufo2map", os.X_OK)
False
>>os.system(".. \..\ufo2map")
---- ufo2map 1.0 ----
0
Is there any workaround in Python or I have to stick with platforms-
specific quirks?
I'm using Python 2.4.2

Thanks!.

--
--t.

Feb 10 '07 #1
3 2092
En Sat, 10 Feb 2007 06:03:40 -0300, techtonik <te*******@gmai l.com>
escribió:
Hello, everyb.

Does anybody know simple cross-platform method of probing if
executable binary is available and launching it.
Problem no.1: test if executable file is available
I'll take windows platform as the most relevant in this case.
os.access() doesn't handle env PATHEXT and can't detect if a given
path would be executable or not. Here "executable " means file that
could be be launched by system() (if there are any other ways - I'd be
happy to know them)

Suppose I have "ufo2exe" executable two directories up.
>>>os.access(". ./../ufo2map.exe", os.X_OK)
True

However...
>>>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.
>
But...
>>>os.system(". .\..\ufo2map")
---- ufo2map 1.0 ----
0
(Beware of single \ on normal strings!)
Use win32api.FindEx ecutable; should return the full path to ufo2map.exe.
"foo.txt" would return notepad.exe (or whatever you have associated to
text files). That is exactly what would be launched by os.system("foo. txt")
Problem no.2: launch executable file
The same windows platform again. All python commands are using forward
slashes for paths, but system doesn't handle this situation (it could
at least try to convert immediate forward slashes to backwards)
Use os.path.normpat h on the filename. (If you got it from FindExecutable
above, that would not be needed)
os.access() thinks this file is executable, but os.system() fails ...
>>>os.access(". ./../ufo2map.exe", os.X_OK)
True
>>>os.system(". ./../ufo2map.exe")
'..' is not recognized as an internal or external command,
operable program or batch file.
1

the contrary - access() fails to tell this path can be launched, but
file Is executable, ...
>>>os.access(". .\..\ufo2map", os.X_OK)
False
Same as above - such file does not exist.
>>>os.system(". .\..\ufo2map")
---- ufo2map 1.0 ----
0
Is there any workaround in Python or I have to stick with platforms-
specific quirks?
I'm using Python 2.4.2
I think you will have to treat each platform differently. Just for
starting, the concept of "executable " is not the same across platforms.
But you could make some generic functions (with different implementations
on different platforms).

--
Gabriel Genellina

Feb 10 '07 #2
On Feb 10, 12:03 pm, "Gabriel Genellina" <gagsl...@yahoo .com.ar>
wrote:
Does anybody know simple cross-platform method of probing if
executable binary is available and launching it.
Problem no.1: test if executable file is available
I'll take windows platform as the most relevant in this case.
os.access() doesn't handle env PATHEXT and can't detect if a given
path would be executable or not. Here "executable " means file that
could be be launched by system() (if there are any other ways - I'd be
happy to know them)
Suppose I have "ufo2exe" executable two directories up.
>>os.access(" ../../ufo2map.exe", os.X_OK)
True
However...
>>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. 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.
>
But...
>>os.system(".. \..\ufo2map")
---- ufo2map 1.0 ----
0

(Beware of single \ on normal strings!)
Use win32api.FindEx ecutable; should return the full path to ufo2map.exe.
"foo.txt" would return notepad.exe (or whatever you have associated to
text files). That is exactly what would be launched by os.system("foo. txt")
Why isn't it possible to integrate the functionality in os.access() -
IIUC Python interpreter still uses Windows API itself on this
platform.
Problem no.2: launch executable file
The same windows platform again. All python commands are using forward
slashes for paths, but system doesn't handle this situation (it could
at least try to convert immediate forward slashes to backwards)

Use os.path.normpat h on the filename. (If you got it from FindExecutable
above, that would not be needed)
os.access() thinks this file is executable, but os.system() fails ...
>>os.access(" ../../ufo2map.exe", os.X_OK)
True
>>os.system(" ../../ufo2map.exe")
'..' is not recognized as an internal or external command,
operable program or batch file.
1
the contrary - access() fails to tell this path can be launched, but
file Is executable, ...
>>os.access(".. \..\ufo2map", os.X_OK)
False

Same as above - such file does not exist.
Same as above - access() tests path, not file, so the argument is not
valid.
>>os.system(".. \..\ufo2map")
---- ufo2map 1.0 ----
0
Is there any workaround in Python or I have to stick with platforms-
specific quirks?
I'm using Python 2.4.2

I think you will have to treat each platform differently. Just for
starting, the concept of "executable " is not the same across platforms.
But you could make some generic functions (with different implementations
on different platforms).
I would prefer to know as little about underlying platforms as
possible.
It would only be a big plus for Python.

--
--t.

Feb 10 '07 #3
En Sat, 10 Feb 2007 08:48:31 -0300, techtonik <te*******@gmai l.com>
escribió:
On Feb 10, 12:03 pm, "Gabriel Genellina" <gagsl...@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

Feb 11 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2054
by: Web Science | last post by:
Site and Features: http://www.eigensearch.com Search engine, eigenMethod, eigenvector, mathematical, manifolds, science, technical, search tools, eigenmath, Jacobian, quantum, mechanics, manifolds, science, physics, chemistry, law, legal, government, home, office, business, domain lookup, medical, travel, food, university students, searching, searchers, surfing, advanced search, search tools Chemistry, mathematics, physical sciences,...
16
2274
by: JustSomeGuy | last post by:
I have a routine that evaluates a polynomial equation that have 3 variables x,y,z of orders 1,2,3 the coefficients of the polynomial are in an array. This routine is quite slow and I'd like to optimize it. Any suggestions? simply put pts is a vector of typdef struct double x; double y; double z;
2
2985
by: News | last post by:
Folks, I need help with this task. I have a set of data that needs to be plotted on timeline chart. Example: Unit ProcStart ProcEnd Machine U1 5/5/03 6:01 5/5/03 6:04 M1 U2 5/5/03 6:03 5/5/03 6:05 M1 U3 5/5/03 6:03 5/5/03 6:04 M2 : etc. There are about 40K units and 30 serving machines. The data is in
0
1893
by: Web Science | last post by:
Site and Features: http://www.eigensearch.com Search engine, eigenMethod, eigenvector, mathematical, manifolds, science, technical, search tools, eigenmath, Jacobian, quantum, mechanics, manifolds, science, physics, chemistry, law, legal, government, home, office, business, domain lookup, medical, travel, food, university students, searching, searchers, surfing, advanced search, search tools Chemistry, mathematics, physical sciences,...
3
2809
by: amanda | last post by:
Hope someone can help me with this - I've been staring at it stupidly for hours now, convinced there must be an easy way to achieve the results I want: I have a very large table recording every sale made by one of 90 salespeople (2 years of data), and the date the sale was made. I need a report that shows a list of the salespeople down the left hand side and then for each month the total number of sales and the total value of sales. I...
23
6543
by: Jeff Rodriguez | last post by:
Here's what I want do: Have a main daemon which starts up several threads in a Boss-Queue structure. From those threads, I want them all to sit and watch a queue. Once an entry goes into the queue, grab it and run a system command. Now I want to make sure that system command doesn't hang forever, so I need some way to kill the command and have the worker thread go back to work waiting for another queue entry.
0
2059
by: Web Science | last post by:
Site and Features: http://www.eigensearch.com Search engine, eigenMethod, eigenvector, mathematical, manifolds, science, technical, search tools, eigenmath, Jacobian, quantum, mechanics, manifolds, science, physics, chemistry, law, legal, government, home, office, business, domain lookup, medical, travel, food, university students, searching, searchers, surfing, advanced search, search tools Chemistry, mathematics, physical sciences,...
2
2975
by: P2P | last post by:
Hi I am wondering if someone know of a free cross-browsers vertical scrolling script that - is cross cross-browsers - will call the scrolling content from an external html page or from a url page
1
1347
by: Sebastian Spandauer | last post by:
Hey, i am searching for a php script that features sending a lets say 20 lesson online course. it should: subscription on website opt-in after subsriciption send one lesson per day to every subscriber first lesson on the day of subscription
6
3991
by: ampo | last post by:
Hello. Can anyone help with cross-domain problem? I have HTML page from server1 that send xmlHTTPRequest to server2. How can I do it? Thanks.
0
9353
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9975
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9909
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8794
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7342
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6623
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5384
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3481
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2765
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.