2

When I run any sudo command using shell-command—for example, (shell-command "sudo ls")—I get the following error:

sudo: no tty present and no askpass program specified

How can I get around this? I'm guessing it should be possible to tell Emacs somehow what my askpass program is?

By the way, the correct askpass program is currently stored in the environment variable $SSH_ASKPASS.

sid-kap
  • 544
  • 1
  • 6
  • 13
  • The environment variables outside of Emacs are passed on to the shell commands. According to sudo's man, it uses the variable SUDO_ASKPASS or the option -A. – Michaël Dec 25 '16 at 10:18

1 Answers1

5

When default-directory points to a sudo-ized path, shell-command uses this environment. Try

(let ((default-directory "/sudo::"))
 (shell-command "ls"))

The password will be asked interactively.

Michael Albinus
  • 6,647
  • 14
  • 20
  • Great, that works! Is there a way to make the output buffer stay visible if the command exits with a failure? – sid-kap Dec 26 '16 at 17:05
  • `shell-command` is just for getting the output as string. For more complex scenarii, `process-file` might be better suited. – Michael Albinus Dec 27 '16 at 09:38