[Top][All Lists]

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

retrieving output from temp file

From: Dan Davison
Subject: retrieving output from temp file
Date: Sun, 21 Feb 2010 11:39:33 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

I want to retrieve the contents of a file created by a shell process,
which might be running remotely. My code (below) works, but I am trying
to learn how to use tramp, and I think that this is not how it would be
done by someone who knew what they were doing.

--8<---------------cut here---------------start------------->8---
(defun retrieve-output ()
  (let ((default-directory "/address@hidden:dirpath")
        (output-file (make-temp-file "zzz-")))
    (shell-command (format "hostname > %s" output-file))
     (if (file-remote-p default-directory) (make-remote-file-name output-file) 

(defun make-remote-file-name (file)
  (let* ((vec (tramp-dissect-file-name default-directory))
         (user (tramp-file-name-user vec))
         (host (tramp-file-name-host vec)))
    (concat "/" user (when user "@") host ":" file)))

--8<---------------cut here---------------end--------------->8---

If default-directory is not remote, then I want this to work for someone
who does not have tramp installed (because aIui an XEmacs user might not
have tramp?)

In my case I *do* need to store the output in a file. I.e. although in
the example above the output is created by redirecting stdout to file,
in general the output of the remote process will not be on stdout (the
output file will be created in some other way by the shell process).

One thing that feels like a hack is the way that, when the process runs
remotely, I manually convert the temp file path into a remote file path.

Another problem is that with my code there is no guarantee that the temp
file name doesn't already exist on the remote host.

Thanks a lot,


reply via email to

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