App.open() won't throw exception?

Asked by Paul Bellamy

I'm trying to right some code that will launch firefox on windows machines. On 64-bit windows, the path to firefox is "C:\Program Files (x86)\Mozilla Firefox\firefox.exe", but on 32-bit windows it's "C:\Program Files\Mozilla Firefox\firefox.exe" (different names for 'Program Files' directory).

So I wrote something like this:

path32 = "C:\\Program Files\\Mozilla Firefox\\firefox.exe"
path64 = "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"

try:
    App.open(path32)
except:
    App.open(path64)

When I run this on a 64-bit machine, sikuli reports an error when it attempts the try statement:

[error] App.open failed: C:\Program Files\Mozilla Firefox\firefox.exe not found.

However, it skips straight over the except statement and continues as if nothing had happened. Am I doing something wrong here? I'm sure I could use another approach to check the path before attempting to open, but it seems as if this approach should work as well.

Thank you for your time,

Paul

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

App.open() does not throw an exception, so try does not work.

try instead:

if not App.open(path32):
    App.open(path64)

because App.open() returns None in case, the app cannot be opened.

Revision history for this message
Paul Bellamy (pbellamy) said :
#2

Thanks as always!

Revision history for this message
Paul Bellamy (pbellamy) said :
#3

Thanks RaiMan, that solved my question.