1

I have a Python script which leverages subprocess to call MobaXterm and use it to run a command to my server through SSH. The script works fine when using the Windows Subsystem for Linux (WSL), but fails when using Moba. This is the code:

import subprocess

moba_path = "C:\Program Files (x86)\Mobatek\MobaXterm\MobaXterm.exe"
subprocess.run(f'{moba_path} -exec ssh my_server "mkdir test_dir"')

It opens the MobaXterm window but does not show any sign of command execution. I checked, and the command has not been executed (the folder has not been created).

Any ideas?

itscarlayall
  • 128
  • 1
  • 14
  • try this because it's working for me subprocess.Popen(["ssh", "%s" % HOST, COMMAND], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) – Osamazx Aug 21 '20 at 13:43
  • That only uses the "ssh" installed in my Windows system. The thing is my ssh configuration is very convoluted and I would prefer to use Moba or WSL (some Linux system) since I already know the configurations there. – itscarlayall Sep 01 '20 at 06:33

1 Answers1

2

So I found a way to execute my commands using Moba in a programmatic way using the -newtab command. It starts a new tab which then runs the specified command.

import subprocess

moba_path = "C:\Program Files (x86)\Mobatek\MobaXterm\MobaXterm.exe"
subprocess.run(f'{moba_path} -newtab ssh my_server "mkdir test_dir"')
itscarlayall
  • 128
  • 1
  • 14