简体   繁体   中英

How would you store the output of exec_command in paramiko with python

import paramiko
import re
import getpass
username=raw_input("Enter the username: ")
password=getpass.getpass(prompt="Enter your password: ")
client = paramiko.client.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.load_system_host_keys()
client.connect(host,22,username,password)
stdin, stdout, stderr= client.exec_command('cat /etc/dhcp/dhcpd.conf')

I'm looking to get the output of dhcpd.conf save it to a variable to parse and get the info that I need. I know that I cant print stdout and get the information that I am looking for but I do not see another way to send it to a variable.

This is in python 2.6.6 . Any help Is appreciated.

stdin,stdout,stderr是文件处理程序。您可以使用stdout.read() or stdout.readlines()读取输出。可以将其分配给变量

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM