我有一个实用功能:
(defun execute-in-buffer (command-with-args buffer)
"Execute a string COMMAND-WITH-ARGS representing a shell command with arguments,
inserting the results in BUFFER."
(switch-to-buffer buffer)
(insert (format ">>> %s\n" command-with-args))
(let* ((command-args-list (s-split " " command-with-args))
(command (car command-args-list))
(args (cdr command-args-list)))
(apply 'call-process command nil buffer t args)))
这让我可以做类似的事情(execute-in-buffer "ls /" (get-buffer-create "*my-output*")
。但是,它不太适合慢速命令。如果我调用一系列缓慢的命令,直到最后我都不会得到任何输出:
(let ((buf (get-buffer-create "*my-output")))
(execute-in-buffer "sleep 10" buf)
(execute-in-buffer "ls /" buf))
我希望能够同步调用,因此下一个命令仅在上一个命令完成后运行。但是,我想在我的命令运行时查看它们的输出。我该怎么做?
(示例代码仅供展示,我很乐意放弃它以支持其他内容。)