def run_as_stream(self, command, logpath):
"""
runs a command over SSH on the client as a stream.
i.e. for every line written by the client during running of command write this to logfile
do not stop untill ssh has no more lines to write
returns -- the output of the command as a string
"""
(ins, stdout, stderr) = self.client.exec_command(command)
f = open(logpath, "a+")
for line in stdout.readlines():
print line
f.write(line)
for line in stderr.readlines():
print line
f.write(line)
评论列表
文章目录