help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Maybe we can improve this function call-process-to-string?


From: Jean Louis
Subject: Re: Maybe we can improve this function call-process-to-string?
Date: Thu, 8 Apr 2021 21:40:22 +0300
User-agent: Mutt/2.0.6 (2021-03-06)

* Stefan Monnier <monnier@iro.umontreal.ca> [2021-04-08 20:50]:
> Also the above code forgot to kill the buffer you created.
> I recommend `with-temp-buffer` here instead:
> 
>     (with-temp-buffer
>       (apply #'call-process program infile t display args)
>       (buffer-string))

Thanks, that now is fully Emacs style. I know this all as tools, but
still need getting used to the tools in the environment.

(defun call-process-to-string (program &optional infile display &rest args)
  (with-temp-buffer
    (apply #'call-process program infile t display args)
    (buffer-string)))

(call-process-to-string "ls" nil nil "-lS" "/tmp/pies.ctl") ⇒ "srwx------ 1 
admin admin 0 Apr  6 11:01 /tmp/pies.ctl
"

-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://rms-support-letter.github.io/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]