Ssh Not Recognized As A Command When Executed From Python Using Subprocess?
This is my code - import subprocess import sys HOST='xyz3511.uhc.com' # Ports are handled in ~/.ssh/config since we use OpenSSH COMMAND='uptime' ssh = subprocess.Popen(['ssh', '
Solution 1:
Apparently this happens in python3. Workaround found at this link: https://gist.github.com/bortzmeyer/1284249
system32 = os.path.join(os.environ['SystemRoot'], 'SysNative' if platform.architecture()[0] == '32bit' else 'System32')
ssh_path = os.path.join(system32, 'OpenSSH/ssh.exe')
out1, err1 = Popen([ssh_path, "pi@%s"%self.host, "%s"%cmd],
shell=False,
stdout=PIPE,
stderr=PIPE).communicate()
Post a Comment for "Ssh Not Recognized As A Command When Executed From Python Using Subprocess?"