Linux: command to open URL in default browser

2019-01-16 11:02发布

What command we have to execute (from Java, but that should not matter) on Linux (different common distributions) to open a given URL in the default browser?

9条回答
孤傲高冷的网名
2楼-- · 2019-01-16 11:31

I think a combination of xdg-open as described by shellholic and - if it fails - the solution to finding a browser using the which command as described here is probably the best solution.

查看更多
小情绪 Triste *
3楼-- · 2019-01-16 11:32

In Java (version 6+), you can also do:

Desktop d = Desktop.getDesktop();
d.browse(uri);

Though this won't work on all Linuxes. At the time of writing, Gnome is supported, KDE isn't.

查看更多
成全新的幸福
4楼-- · 2019-01-16 11:38

At least on Debian and all its derivatives, there is a 'sensible-browser' shell script which choose the browser best suited for the given url.

http://man.he.net/man1/sensible-browser

查看更多
登录 后发表回答