Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use Powershell as my tramp-encoding-shell?

First I start up eshell then I enter the command cd /plink:<user>@<host>:/home/

then I get this error message

Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved.

The command prompt has been disabled by your administrator.

Press any key to continue . . .

I am trying to connect with plink (which is in my path), also after going through the *Messages* buffer I found this.

Couldn't find local shell prompt for (C:\Windows\system32\cmd.exe)

I'm 90% sure that this is because the cmd has been disabled on my machine, because when I try the same setup on a different computer, where I know the cmd is enabled, everything works.

I've modify my .emacs file to have

(require 'tramp)
(set 'tramp-encoding-shell "C:/Windows/System32/WindowsPowershell/v1.0/powershell.exe")
(set 'tramp-encoding-command-switch "-Command")

I get different results, however the results appear to be scrambled nonsense (the third line looks like it could be a prompt, the \ and > characters are in the correct places...).

emacs error

I managed to dig up a pretty good description of what tramp-encoding-shell is, there's also a related SO question, and here is the tramp-encoding-shell source/documentation on github.

Update

Here is what my screen looks like after trying to unsuccessfully open a plink connection with powershell set as the tramp-encoding-shell.

fullscreen screenshot

like image 814
John Avatar asked Apr 30 '15 14:04

John


1 Answers

So I dont know TRAMP but the explanation of what you get is that Windows PowerShell send you back unicode (UTF16), each character is 16 bits in this case the letter an a zero, plus the fact that the End Of Line is carriage return / line feed (0xa, Oxd).

Now for "emacs could not find local shell prompt for PowerShell" error according to TRAMP documentation @Michael Albinus advice seems to be promising.

6.4.2 Running shell on a remote host

Calling M-x shell in a buffer related to a remote host runs the local shell as defined in shell-file-name. This might be also a valid file name for a shell to be applied on the remote host, but it will fail at least when your local and remote hosts belong to different system types, like ‘windows-nt’ and ‘gnu/linux’.

You must set the variable explicit-shell-file-name to the shell file name on the remote host, in order to start that shell on the remote host.

6.4.6 Running remote processes on Windows hosts With the help of the winexe it is possible tu run processes on a remote Windows host. TRAMP has implemented this for process-file and start-file-process.

The variable tramp-smb-winexe-program must contain the file name of your local winexe command. On the remote host, Powershell V2.0 must be installed; it is used to run the remote process.

In order to open a remote shell on the Windows host via M-x shell, you must set the variables explicit-shell-file-name and explicit-*-args. If you want, for example, run cmd, you must set:

(setq explicit-shell-file-name "cmd"
      explicit-cmd-args '("/q"))

In case of running powershell as remote shell, the settings are

(setq explicit-shell-file-name "powershell"
      explicit-powershell-args '("-file" "-"))
like image 191
JPBlanc Avatar answered Nov 01 '22 02:11

JPBlanc