J'ai scanné "python ssh". Il y a un merveilleux module pexpect
, qui peut accéder à un ordinateur distant en utilisant ssh (avec mot de passe). Une fois l'ordinateur distant connecté, je peux exécuter d'autres commandes.comment obtenir la sortie de la console à partir d'un ordinateur distant (ssh + python)
Cependant, je ne peux pas obtenir le résultat en python à nouveau.
p = pexpect.spawn("ssh [email protected]_computer")
print "connecting..."
p.waitnoecho()
p.sendline(my_password)
print "connected"
p.sendline("ps -ef")
p.expect(pexpect.EOF) # this will take very long time
print p.before
Comment obtenir le résultat de ps -ef
dans mon cas?
hmm? p.before devrait donner la sortie –
python retourne "None" – stanleyxu2005