Skip to main content
3 of 4
explanation now correct and it looks nicer
jue
  • 4.7k
  • 10
  • 21

kill-process is working in your case. But the loop is to fast. The first get-buffer-process next to while returns, right after killing cat, the handle to the cat buffer, but the next get-buffer-process near kill-process is returning nil. So kill-process tries to kill a different buffer (e.g.: "scratch").

A solution would be:

(let ((buf
       "*Async Shell Command*"))
  (async-shell-command "cat")
  (while (get-buffer-process buf)
    (message "still has proc")
    (kill-process (get-buffer-process buf))
    (sit-for 1)))

Another solution could be this:

(let ((buf
          "*Async Shell Command*"))
     (async-shell-command "cat")
     (while (not (string= (kill-process buf) buf))
       (sit-for 1)
       (message "still has proc")))
jue
  • 4.7k
  • 10
  • 21