Renaming a file error?

I have a function to compress my pdf file using pdftk:

(defun compresspdf (filename)
  (interactive)
  (let ((tmpfile (concat filename "~")))
    (start-process-shell-command "pdftk" nil
    (format "pdftk %s cat output %s compress dont_ask"
        filename tmpfile))
    (rename-file tmpfile filename t)))

It compresses the file and saves it as the same name with the addition ~. However, at the point where the file is supposed to be renamed, this gives me an error: let: Renaming: No such file or directory, /pathtofile/mypdf.pdf~, /pathtofile/mypdf.pdfalthough it is obvious that both of these files exist. After that, I can separately evaluate the rename file, and it works fine. Maybe he is trying to rename the file ~before creating it? In this case, how can I make it wait until the process is complete? (and maybe check for errors?)

+3
source share
1 answer

'start-process-shell-command, , tmpfile. 'shell-command, :

(defun compresspdf (filename)
  (interactive)
  (let ((tmpfile (concat filename "~")))
    (with-temp-buffer 
      (shell-command (format "pdftk %s cat output %s compress dont_ask"
                             filename tmpfile)
                     (current-buffer)
                     (current-buffer)))
    (rename-file tmpfile filename t)))

'shell-command ( ).

+3

Source: https://habr.com/ru/post/1762869/


All Articles