FindExecutable replacement for Linux application to open HTML files at anchor. lazarus / 1-Linux ---------------------------------------------------------------------- han · 2016-06-02 13:58 To open local HTML files and jump to an anchor in the text, I need direct access to the browser executable. With following command I can jump to an anchor in a local HTML file:     firefox "file:///documentation.html#anchorname" This commando can't pass through opendocument(documentation.html#anchorname) unless the anchor is removed. It works however in openURL() for webpages but not for local HTML files. I have a robust solution for MSWindows below but not for Linux. Somehow I have to find out where the executable of the browser is located. I can simple use something like  if FileExists('/usr/bin/firefox') then browser:='/usr/bin/firefox' but that is not a robust solution. See code below. Any ideas for a Linux equivalent for  FindExecutable? If I look to the properties of an HTML file, the system knows to browser application to open it. How to extract this information from the Linux operating system? My procedure: procedure open_file_with_parameters(filelink,parameters2:string);{This one does work for anchor parameters. Works for chrome and Firefox, not for internet explorer}  {$ifdef unix} var   AProcess: TProcess;   browser :string; begin   {FindExecutable not available in Linux, workaround:}   if FileExists('/usr/bin/firefox') then browser:='/usr/bin/firefox' else   if FileExists('/usr/bin/seamonkey') then browser:='/usr/bin/seamonkey' else   if FileExists('/usr/bin//google-chrome') then browser:='/usr/bin/google-chrome' else   if FileExists('/usr/bin/opera') then browser:='/usr/bin/opera' else browser:='';   if browser<>'' then   begin     AProcess := TProcess.Create(nil);     AProcess.Executable := browser;     AProcess.Parameters.Add('file:///'+filelink+parameters2);     // AProcess.Options are not set so the program continues after starting the browser}     AProcess.Execute;     AProcess.Free;   end   else   OpenDocument(Filelink);{unknown browser, open without anchor} end; {$ELSE} {windows}  var     Buffer: array[0..MAX_PATH] of     Char;     Res: Integer;   begin   FillChar(Buffer, SizeOf(Buffer), #0);   Res := FindExecutable(PChar(filelink), nil, Buffer );   if Res > 32 then {Executable program for filelink is in Buffer}   begin     ShellExecute(mainwindow.handle, 'open', buffer, PChar('"'+'file:///'+filelink+parameters2+'"'),nil, SW_SHOWNORMAL)  {file:///  for firefox, otherwise # becomes %23,  '"' for paths with spaces like program files}   end; end;  {$endif}