【发布时间】:2011-01-29 03:50:00
【问题描述】:
我正在尝试为一些常用的 sudo shell 命令创建快捷键(例如,让C-c s 运行(shell-command "sudo /etc/init.d/apache2 restart"))。
我尝试使用上述的直接 shell 命令调用,但它只是将以下内容输出到 *Shell Command Output* 缓冲区:
[sudo] password for Inaimathi:
Sorry, try again.
[sudo] password for Inaimathi:
Sorry, try again.
[sudo] password for Inaimathi:
Sorry, try again.
sudo: 3 incorrect password attempts
它实际上并不要求输入密码。我不想必须使用sudo emacs 启动 Emacs,但我想如果没有其他方法可行的话,这是一个选择。
理想的解决方案是 Emacs 中的一个函数(而不是 OS jiggery-pokery 来改变 shell 的行为或 sudo 命令)。类似(sudo-shell-command "dostuff") 或(with-password-prompt (shell-command "sudo dostuff"))。
【问题讨论】:
-
相关(几乎重复?):stackoverflow.com/questions/95631/… 并且对迁移到超级用户的投票可能是正确的。 @Inaimathi:如果这与编程密切相关,现在是解释原因的好时机,或者这个问题可能会转移到更合适的网站。
-
鉴于 OP 试图将一些 elisp 绑定到一个键,这对我来说已经足够编程了。
-
重组问题以减轻一些混乱。
-
你不用这个。您可以使用 TRAMP,
/sudo::/etc/init.d/apaches2打开文件,然后使用M-x shell从该文件启动 shell。