kill-process
is working in your case. But the loop is to fast.
The firstfor a reason get-buffer-process
nextdoes not return nil to while
returns, right after killing cat
, the handle. Maybe because it refers to the cat
a buffer which is not yet closed, but the next get-buffer-process
nearand emacs needs to take a breath? A killsit-process
is returning nilfor
. So kill-process tries to kill a different buffer (e.g.: "scratch") command will fix this.
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 10.01)))
Another solution could be thisnot to use get-buffer-process
:
(let ((buf
"*Async Shell Command*"))
(async-shell-command "cat")
(while (not (string= (kill-process buf) buf))
(sit-for 1)
(message "still has proc")))