[Top][All Lists]

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

Re: retrieving output from temp file

From: Michael Albinus
Subject: Re: retrieving output from temp file
Date: Sun, 21 Feb 2010 18:57:51 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.92 (gnu/linux)

Dan Davison <address@hidden> writes:

> 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.

What about

  (process-file "process" nil t)

> 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?)

It works also for a local `default-directory'. XEmacs comes with Tramp
2.0, but it doesn't know `process-file' (yet).

> 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).

This case, I would do

  (defun retrieve-output ()
    (let ((tmpfile
            (concat (file-remote-p default-directory) "/tmp/zzz-"))))
             "process" nil nil nil
             (or (file-remote-p tmpfile 'localname) tmpfile))
            (insert-file-contents tmpfile))
        (delete-file tmpfile))))


I have added the local file name part of tmpfile to the `process-file'
call; it depends on the "process" command, where it does expect the
output file.

> 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.

`make-temp-file' works also wit a remote prefix, as you see.

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

With this approach, `make-temp-file' does it for you.

> Thanks a lot,
> Dan

Best regards, Michael.

reply via email to

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