I use emacs 24.4.1 on ubuntu 15.04. Somehow xdg-open doesnot work if i run it from emacs. For example, if i run "xdg-open 1.pdf" or "gvfs-open 1.pdf" in eshell they do not work. At the same time, "evince 1.pdf" works perfectly.


The previous two answers didn't work for me:

  • (setq process-connection-type nil) broke org-plot/gnuplot
  • setsid xdg-open ... worked for a while, but then it stopped for some reason.

Now I use setsid -w, which supposedly makes setsid wait until the called program finishes.

If someone would need it, I use this with AUCTeX (and I found this question while trying to fix AUCTeX behavior on Arch linux), and my TeX-command-list is set to

  ;; ...
  ("View" "setsid -w xdg-open %s.pdf" TeX-run-command t t :help "Run Text viewer")
  ;; ...

It seems to work fine for now...

| improve this answer | |

Using setsid xdg-open 1.pdf works for me. The problem seems to be that gvfs-open and xdg-open return before their children are done working. Emacs might kill their controlling terminal when this happens, killing the children, and stopping evince from opening properly. setsid sets a new controlling terminal that emacs won't close.

| improve this answer | |
  • To make it work I had to include -w (wait): setsid -w xdg-open 1.pdf – Francesquini Mar 10 '19 at 21:34

This may be a problem with using ptys for subprocess communication. Try setting process-connection-type to nil to use pipes instead.

In your .emacs

;; Use pipes for subprocess communication
(setq process-connection-type nil)

I use the publishing functions from org mode and without this change, none of the generated files get opened via xdg-open, despite no error messages.

| improve this answer | |
  • Thanks, it worked! Is there some documentation containing some explanation for this? – Emil Vatai Jan 11 '17 at 10:27
  • This method does work, but might cause problems for other applications (for me it ruined calling gnuplot from org-mode), so it's not an optimal solution! I have Michael Hoffmans solution in my .emacs now (for the view command in Auctex). We'll see how it works. – Emil Vatai Feb 16 '17 at 5:28
  • To reproduce the error mentioned above: try running org-plot/gnuplot with the cursor/point on a table with and without process-connection-type set to nil, for more details see first subsection of this page. – Emil Vatai Feb 16 '17 at 6:43

xdg-open work in sync mode: (shell-command "xdg-open .") , but not in async mode: (async-shell-command "xdg-open .") .

it seem like xdg-open spawn child process to open file then exit. before child process open file, xdg-open exit, so shell exit, too. shell exit kill all child process.

so just make shell life little more: (async-shell-command "xdg-open . ; sleep 1") (async-shell-command will append & after sleep 1 ; anyway, shell will still wait background process & finish.)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.