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.

1
  • 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
    Commented Dec 25, 2016 at 10:18

1 Answer 1

7

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.

2
  • Great, that works! Is there a way to make the output buffer stay visible if the command exits with a failure?
    – sid-kap
    Commented Dec 26, 2016 at 17:05
  • shell-command is just for getting the output as string. For more complex scenarii, process-file might be better suited. Commented Dec 27, 2016 at 9:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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