I\'m trying to check for the existence of an executable on a remote machine, then run said executable. To do so I\'m using subprocess to run ssh
How about using authorized_keys. Then, you don't need to input password.
You can also go hard way (only work in Linux):
import os
import pty
def wall(host, pw):
pid, fd = pty.fork()
if pid == 0: # Child
os.execvp('ssh', ['ssh', host, 'ls', '/usr/bin/wall'])
os._exit(1) # fail to execv
# read '..... password:', write password
os.read(fd, 1024)
os.write(fd, pw + '\n')
result = []
while True:
try:
data = os.read(fd, 1024)
except OSError:
break
if not data:
break
result.append(data)
pid, status = os.waitpid(pid, 0)
return status, ''.join(result)
status, output = wall('localhost', "secret")
print status
print output
http://docs.python.org/2/library/pty.html