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 ~ appended. However, at the point where it's supposed to rename the file, it gives me an error:
let: Renaming: No such file or directory, /pathtofile/mypdf.pdf~, /pathtofile/mypdf.pdf, though clearly, both of these files exist. I can separately evaluate rename-file afterwards and it works fine. Maybe it's trying to rename the ~ file before it's actually created? In that case, how can I make it wait until the process is finished? (and possibly check for errors?)
As opposed to using 'start-process-shell-command, which just spawns the process, so the rename happens before the tmpfile is created. Try using 'shell-command, like so:
(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)))
The call to 'shell-command will finish after the process is done (compression is complete).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With