1

To better integrate my Windows DevOps into Emacs Org-mode, I'd like to use my local emacs as an IDE for a remote Powershell.

SSH was easily setup, from Linux shell ssh I can successfully login to a powershell shell as a domain user, and run commands, without password, using keys. Non-ASCII characters like 'é' work, and TAB works as usual in cmd and powershell.

I routinely run code blocks on Linux systems via SSH, so I tried:

#+NAME: PSH-Test
#+HEADER: :dir "/ssh:MyWinPC:~/"
#+BEGIN_SRC shell
  ipconfig
#+END_SRC

When I run the above, I get queried for my remote password, and then I get a message

Tramp: Found remote shell prompt on MyWinPC

Emacs then hangs until I press C-g.

In *scratch* I then executed (setq tramp-verbose 10), and retried. In the debug output buffer I could see my remote prompt, so login seems to have worked, and there was a message indicating, that /bin/sh could not be loaded. So I am assuming this to be the/a problem.

Do I need winexe, If i can successfully ssh?

Using sh, shell, or powershell as code block language makes no difference. I installed a package for powershell from the package manager.

So, How do I correctly call/execute PowerShell/CMD commands/scripts from linux emacs org-mode code blocks on remote Windows 7+ Hosts via SSH?

Note: In the meantime I use the workaround of wrapping all windows devops scripts into a linux shell block, that does ssh as first step, but that feels ugly.

  • According to org-mode user manual, language abbreviation should be "sh" for shell, so #+BEGIN_SRC sh. Take care you need to (require 'ob-shell) in your configuration, if your org version is >8.2 – Ian Apr 18 '18 at 13:15
  • @Ian: in the same document, and others, I have shell-blocks and blocks for other languages as well, that i can successfully execute, so thank you for your suggestion, but I think, my problem lies elsewhere. – Alex Stragies Apr 18 '18 at 18:08
  • Did you figure this out? If you ssh directly, without emacs, into MyWinPC do you get a shell? – Melioratus Apr 17 at 16:55
  • @Melioratus Thx for the +1. No, I did not figure this out, and I do not currently manage windows hosts. But it will happen again soon, so I will be trying to figure this one out. At the time, i was able to log into my windows hosts from shell level into shell level, without password. At the time i choose wrapping my windows powershell in linux scripts, that ssh as first step. I will edit the post to make this clearer. Feel free to mark this comment as obsolete when seen. – Alex Stragies Apr 18 at 11:13
  • Thanks for the reply!! I suspect doing Literate DevOps on Windows would be really useful for the community. I wonder if your issue was caused by the environment on windows. My guess is that the SRC block stalled creating the temporary script on the windows filesystem. Also I wonder if adding :session session-name header to your SRC block would provide additional debug output in a buffer named session-name. – Melioratus Apr 18 at 18:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.