I have the following code which runs good on a remote Unix server and completes the task through ssh.exec_command(). But, I want to store the log in a text file in my Windows PC from where it is being executed. How do I redirect the output of stdout_data and stderr_data to two different txt files which I can store as a future log?
#!/usr/bin/env/python
import paramiko
trans = paramiko.Transport(('fcd01.force.com',22))
trans.connect(username = 'user',password = 'pwd')
session = trans.open_channel("session")
session.exec_command('cd /project/fcd_neptune_psv/akar/neptune_psv/fw; ./Do_Regr.sh -i Testlist_Regression.in -m 135.24.237.167 -g')
stdout_data = []
stderr_data = []
while True:
if session.recv_ready():
stdout_data.append(session.recv(4096))
if session.recv_stderr_ready():
stderr_data.append(session.recv_stderr(4096))
if session.exit_status_ready():
break
print 'exit status: ', session.recv_exit_status()
print ''.join(stdout_data)
print ''.join(stderr_data)
session.close()
trans.close()