开发者

Opening a file with the default viewer on Linux

I am working at an OS independent file manager (mostly Windows and Linux), and I am wondering if there is a Linux way to open a file in its default viewer. For example, open a html file with Firefox, an .avi with vlc, and so on. On Windows, there is a function ShellExecute() that does that, but my understanding is that on Linux it is not that simple, an开发者_C百科d each desktop environment has a specific way. I would appreciate any help with this.


You could use xdg-open(1). It works on all freedesktop compliant desktops.


The default programs for different mime-types are defined in /etc/mailcap and $HOME/.mailcap, indexed by file type and action (display, edit, print). The command line interface is run-mailcap. See also the manpages run-mailcap(1) and mailcap(5).


It depends what desktop environment you're using in Linux. Gnome for example has a MIME database you can use to find out what to launch for a given file.


Sahil Muthoo has given you good advice. I will just give further examples.

If xdg-open is not available you can also use "gnome-open" for GNOME and "kfmclient" for KDE.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜