[Top][All Lists]

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

Re: retrieving output from temp file

From: Dan Davison
Subject: Re: retrieving output from temp file
Date: Thu, 25 Feb 2010 13:50:00 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

Michael Albinus <address@hidden> writes:

> 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
>            (make-temp-file
>             (concat (file-remote-p default-directory) "/tmp/zzz-"))))
>       (unwind-protect
>           (progn
>             (process-file
>              "process" nil nil nil
>              (or (file-remote-p tmpfile 'localname) tmpfile))
>             (insert-file-contents tmpfile))
>         (delete-file tmpfile))))
>   (retrieve-output)
> 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.

Hi Michael,

I'm having problems applying the above advice. Specifically, my problem
is with make-temp-file:

(make-temp-file "/yakuba:/tmp/tramp" t)
;; OK -- makes remote dir without error

(make-temp-file "/yakuba:/tmp/tramp")
(tramp-compat-make-temp-file "/yakuba:/tmp/tramp")
;; Both make local file in /tmp with error
;; Wrong type argument: number-or-marker-p, ""

I'm confused that both these made a *local* temp file.

The reason for the error seems to be as follows:

| Both make-temp-file and tramp-compat-make-temp-file call write-region with 
START arg set to ""
| From write-region:
| If start is a string, then output that string to the file
| instead of any buffer contents; end is ignored.
| line 4431 tramp.el tramp-handle-write-region
|                    (> (- (or end (point-max)) (or start (point-min)))

Thanks very much for all your help so far.

This is emacs 23.1.1 tramp 2.1.15 on ubuntu 9.10


>> Thanks a lot,
>> Dan
> Best regards, Michael.

reply via email to

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