I am writing an application with a server client type of framework. To implement the logic,
- I need to transfer a zipped folder to a Windows server,
- unzip the folder and
- then run a certain python file within the folder.
I am trying to recreate the steps manually, so that I can then redo it using
python libraries (such as paramiko
and zipfile
or other python libraries)
So far I have tried the following tests to check whether I can reliably run a python script using ssh:
Using OpenSSH from Windows 10: https://github.com/PowerShell/Win32-OpenSSH/wiki/Install-Win32-OpenSSH After some configuration, I was able to copy files from the client side to the server using
scp
. The next plan was to use ssh to remotely run a specific file usingpython filename.py
Then cd'ed into the folder and tried running python filename.py. However, there was no output from
python
.Next I tried MobaSSH, and the problem was the same as the test with OpenSSH from Microsoft. `Fatal Python error: Py_Initialize: can't initialize sys standard streams LookupError: unknown encoding: cp28591
Current thread 0x00000874 (most recent call first):`
From the above 2 experiments, I initially thought there was a problem with my python installation. So I directly logged into the machine, and use
cmd
to run the same file as ,python filename.py
, it does run and produce the expected outputs. So python does run fine on the Windows machineMy next hypothesis was that its impossible to run python if run through SSH. To test this I logged into my ubuntu VM, and did the same experiment. In this case, python ran fine, with no errors.
From these experiments, it seems that if I log into Windows using ssh
, and try
to run python, I cant run it maybe because of a quirk of python or of Windows.
But if I am directly logged into Windows, I can run the same python script
fine. Further, it seems ssh does work flawlessly in a linux environement.
I do need to run the python script in a Windows environment, not a linux environment because of some other considerations. So even though running the test file worked fine in the ubuntu VM, I cant use that environment. .
Is there a way to run a Python script when logged in via SSH in a Windows environment?