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

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

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


From: Jean Louis
Subject: Maybe we can improve this function call-process-to-string?
Date: Thu, 08 Apr 2021 10:40:17 +0300

Hello,

There is function `shell-command-to-string' which is very handy. But
when there are problems with quoting it is better to use
`call-process'. Yet there is no function `call-process-to-string',
which I have made as below.

Maybe people can tell me how to improve this function?

(defun call-process-to-string (program &optional infile display &rest args)
  (let* ((buffer-name "Output")
         (buffer (generate-new-buffer buffer-name))
         (status (apply #'call-process program infile buffer display args))
         (current-buffer (current-buffer))
         (output (if status
                     (progn 
                       (switch-to-buffer buffer)
                       (buffer-string))
                   "")))
    (switch-to-buffer current-buffer)
    output))

(call-process-to-string "identify" nil nil 
"/home/data1/protected/2021-03-27-10:02:52.png")

Is there maybe some other function that can give me string from
buffer?


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]