title: Towards understanding availability of xdg-open
body: <p>I want to open an image, and in Windows I do:</p>
  
  <pre><code>#include &lt;windows.h&gt;
  ..
  ShellExecute(NULL, "open", "https://gsamaras.files.wordpress.com/2018/11/chronosgod.png", NULL, NULL, SW_SHOWNORMAL);
  </code></pre>
  
  <p>I would like to use a Linux approach, where it's so much easier to run something on the fly. Example:</p>
  
  <pre><code>char s[100];
  snprintf(s, sizeof s, "%s %s", "xdg-open", "https://gsamaras.files.wordpress.com/2018/11/chronosgod.png");
  system(s);
  </code></pre>
  
  <p>In my Ubuntu, it works. However, when running that in Wandbox (<kbd><a href="https://wandbox.org/permlink/dCyXUR89QGGTa5A6" rel="nofollow noreferrer">Live Demo</a></kbd>), or in any other online compiler, I would most likely get an error:</p>
  
  <blockquote>
    <p>sh: 1: xdg-open: not found</p>
  </blockquote>
  
  <p>despite the fact that these online compilers seem to live in Linux (<a href="https://stackoverflow.com/questions/142508/how-do-i-check-os-with-a-preprocessor-directive">checked</a>). I don't expect the online compiler to open a browser for me, but I did expect the code to run without an error. Ah, and forget <a href="https://apple.stackexchange.com/questions/248000/why-can-i-not-use-xdg-open-and-gnome-open-in-mac">Mac</a> (personal laptop, limiting my machines).</p>
  
  <p>Since I have no other Linux machine to check, my question is: Can I expect that this code will work in most of the major Linux distributions?</p>
  
  <p>Maybe the fact that it failed on online compilers is misleading.</p>
  
  <hr>
  
  <p>PS: This is for my post on <a href="https://meta.stackexchange.com/a/319020/275467">God of Time</a>, so no worries about security.</p>