python subuprocess: 'ssh' is not recognized as an internal or external command, operable program or batch file

I can run ssh -R 80:localhost:5000 serveo.net command in cmd without any problem, but when i try to run it through Python, it shows me this error:

'ssh' is not recognized as an internal or external command, operable program or batch file.

what can i do to solve this problem?

subprocess.call('ssh -R 80:localhost:5000 serveo.net', shell=True)

1 answer

  • answered 2019-06-25 07:59 Mithilesh_Kunal

    The problem is with the arguments. The final command is to be split with spaces and should be sent as list. To make this work, run the below code.

    subprocess.call(['ssh','-R','80:localhost:5000','serveo.net'], shell=True)