Launch web page from my application in Linux

browser, c, c++, linux

Solution

If you're writing this for modern distros, you can use `xdg-open`:

$ xdg-open http://google.com/

If you're on an older version you'll have to use a desktop-specific command like `gnome-open` or `exo-open`.

Problem

I have an application that launches a webpage in the "current" browser when the user selects it. This part of my app works fine in the Windows version but I can't figure out how to do this in Linux build. Right now the Linux version is hardcoded for Firefox in a specific directory and runs a new instance of it each time and doesn't show the URL that I pass in. I would like it to NOT launch a new version each time but just open a new page in the current open one if it is already running. For windows I use: ``` ShellExecute(NULL,"open",filename,NULL,NULL,SW_SHOWNORMAL); ``` For Linux I currently use: ``` pid_t pid; char *args[2]; char *prog=0; char firefox[]={"/usr/bin/firefox"}; if(strstri(filename,".html")) prog=firefox; if(prog) { args[0]=(char *)filename; args[1]=0; pid=fork(); if(!pid) execvp(prog,args); } ```

Original source