5

If I do:

  (getenv "PATH")

I get a list of colon-separated directories, including:

  /Users/michaeln/Library/Haskell/bin

If I look at the exec-path variable, I see a list including the same directory. If I do:

  (shell-command "echo $PATH")

I get a list of colon-separated directories including the same Haskell/bin directory as above. There is an executable pandoc in that directory. And yet, if I do:

  (shell-command "pandoc")

I get in response:

  /bin/bash: pandoc: command not found

What am I doing wrong?

Scott Weldon
  • 2,695
  • 1
  • 18
  • 31
  • Try adding the path of the folder where pandoc is located to your exec-path: http://emacswiki.org/emacs/ExecPath – lawlist Apr 08 '15 at 05:46
  • are you able to run pandoc from bash shell prompt? – Saravana Apr 08 '15 at 05:53
  • @lawlist I have; as above "If I look at the exec-path variable...". – Michael Norrish Apr 08 '15 at 05:57
  • @MadhavanKumar Yes. If I run M-x shell and type pandoc --version, or if I run my usual shell within Terminal.app. – Michael Norrish Apr 08 '15 at 05:58
  • exec-path is only relevant to binaries Emacs wants to run. In this instance Emacs is running a shell (and the shell is running pandoc), so I believe there's no particular reason in this case for pandoc to be accessible from exec-path. – phils Apr 08 '15 at 07:35
  • This looks weird to me. What does which pandoc report from the shell? – phils Apr 08 '15 at 07:38
  • What if your shell profile overwrites PATH variable? – wvxvw Apr 08 '15 at 12:09
  • where/how are you adding your ../Haskell/bin directory to your path? my guess is that it is getting added dynamically for interactive shells, which (shell-command) is not considered by default. does it work if you set the following: (setq shell-command-switch "-ic")? – waymondo Apr 08 '15 at 14:06
  • @waymondo Yes, that is the key. I'm fairly certain that Emacs inherits the PATH from the shell where it's run. If, for instance, op has export PATH=$PATH:~/Haskell/bin in his .bashrc, but runs Emacs from, say, a desktop icon, it may not inherit the proper path. – nanny Apr 08 '15 at 14:11
  • But notice that (getenv "PATH") returns the directory I want. Nonetheless, I think @waymondo is right: the Haskell/bin directory is added interactively, not for non-interactive shells. – Michael Norrish Apr 10 '15 at 03:34

1 Answers1

5

If you are adding your Haskell bin to your PATH in a .bashrc or similar dotfile, this file only gets loaded when running an "interactive" shell. This happens when running M-x shell but not when running M-! / (shell-command), as there is no prompt. You can adjust the option flags that are sent to (shell-command) by adjusting shell-command-switch to instruct it to act interactively and load your shell dotfile with:

(setq shell-command-switch "-ic")
waymondo
  • 1,384
  • 11
  • 16
  • Curiously, something about my non-interactive bash setup must be setting my PATH rather than extending it: otherwise, surely the non-interactive shell would inherit the PATH variable that emacs has in its own environment. – Michael Norrish Apr 10 '15 at 03:37
  • Now, without changing any of my config files, I can't even reproduce the behaviour. I have rebooted the relevant machine because it just upgraded OS X version. I think the comment about interactive vs non-interactive shells is still very valuable though. Thanks! – Michael Norrish Apr 10 '15 at 03:44