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
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
(quote ( ;; ... ("View" "setsid -w xdg-open %s.pdf" TeX-run-command t t :help "Run Text viewer") ;; ... )
It seems to work fine for now...
setsid xdg-open 1.pdf works for me. The problem seems to be that
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.
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.
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
sleep 1 ;
anyway, shell will still wait background process