대문 최근에 바뀐 글 새소식 찾기 하우투 문제 제안

EshellAndTramp

최근 편집

요약: Added method to run TRAMP remote command from eshell, and return stdout as string.

변경됨:

< This allows you to further process the string within a lisp expression. You can do this for local shell commands with (with-output-as-string) but that doesn't work in eshell when you're using TRAMP in a remote directory. This is how I did it in a remote directory:

(으)로

> This allows you to further process the string within a lisp expression. The key here is to pass standard-output as the 2nd arg to shell-command. That's the only buffer that with-output-to-string will look at. By default the output from shell-command goes elsewhere, and with-output-to-string will come up empty handed.


I’d like to start this node with a question:

I use TrampMode instead of AngeFtp. I cannot, however, see the output of remote commands [ran whilst in a remote directory ie on a remote host] in the eshell buffer.

Kai Großjohann had inquired about the same issue on tramp-devel/2002-09:

http://lists.gnu.org/archive/html/tramp-devel/2002-09/msg00121.html

I was wondering if there is a simple way [ie a simple change or setting in either eshell or tramp] which inserts the output a remote command into the current eshell buffer…

I have it working successfully with TRAMP on a Win32 machine, via PuTTY. Nothing special about my setup, here’s the TRAMPy part:

    (require 'tramp)
    (setq tramp-debug-buffer t)
    (setq tramp-default-method "plink")
    (setq tramp-auto-save-directory (concat "d:\\tmp\\" user-login-name) ; (Windows)

tramp-default-method seems to be the important thing, to save it guessing how to connect. I can then cd like so:

    cd /USER@PUTTYCONFIG:/some/path

So long as the hostname (“PUTTYCONFIG”) has been saved by Putty, it’s fine.

I have not tried with other TRAMP methods like ssh (we’re using Windows to reach into Unix hosts here, I know crazy…) but if the default is set to something that works, I think eshell should be fine.


How to redirect stdout of a remote command to be returned as a string

This allows you to further process the string within a lisp expression. The key here is to pass standard-output as the 2nd arg to shell-command. That’s the only buffer that with-output-to-string will look at. By default the output from shell-command goes elsewhere, and with-output-to-string will come up empty handed.

    (with-output-to-string (shell-command "COMMAND" standard-output))

For example,

     /ssh:myhostname.domain.com:/home/myuser $ (split-string (with-output-to-string (shell-command "hostname" standard-output)) "\\." )
        ("myhostname" "domain" "com\n")