3

I am trying to write a function launchSystemFile which works like windows ShellExecuteEx from the command line or from C++.

If I ShellExecuteEx a blah.txt it opens it in the default editor. If I ShellExecuteEx a firefox.exe it launches the executable.

I have been doing from C++ popen "xdg-open blah" and it works great except for executables.

Is there anyway to make xdg-open execute an executable? Such as Firefox at path /usr/lib/firefox/firefox?

I tried xdg-open "/usr/lib/firefox/firefox" but this fails with the error message:

gvfs-open: /usr/lib/firefox/firefox: error opening location: No application is registered as handling this file

3

xdg-open is just a shell script that detects Desktop Environment and call the corresponding program (gvfs-open for gnome , exo-open for XFCE, mate-open, etc.)

So the limitations for launching an executable are derived from the corresponding launcher of each DE, which is gvfs-open in your case.

Looking at gvfs-open man page, this app (similar to the other DE apps) just calls the default application registered per file type as it is defined by gvfs-mime settings.

In your case , gvfs-open tries (and fails) to find a corresponding application to launch a firefox file.

If you run xdg-open (or gvfs-open) with an html link like https://www.google.com , then should work correctly; gvfs-open will search mime database to find how to handle the html link, mime will advise to call firefox, and firefox will be called.

Looking at xdg-open shell script functions, there are some functions that extract the Exec entry out of the corresponding .desktop file and under some Desktop Environments the command found in Exec section of .desktop file is just executed as it is by xdg-open.

In other words, you do not have to call xdg-open or gvfs-open to launch executables like firefox.

Just launch "firefox" and should be executed (i.e popen "/usr/bin/firefox")

PS: Or you might even need to call (exec firefox &)

You could even extract Exec entries by all .desktop files with a grep loop like this:

for file in "$(find /usr/share/applications/ -type f -name '*.desktop')"; do
executable=$(grep -m1 "^Exec=" <<<"$file") #some files have more than one Exec entries
echo "$file - $executable"
done
  • Thank you George for such a detailed answer! I really appreciate it! – Noitidart Jan 28 '17 at 0:13
  • 1
    @Noitidart Welcome man! Glad if this helped. Thanks for accepting my answer :-) – George Vasiliou Jan 28 '17 at 0:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.