python';将stdout/stderr(在远程服务器上)保存到文件中

python';将stdout/stderr(在远程服务器上)保存到文件中,python,stdout,Python,Stdout,我是Python脚本编写的新手。正在尝试将stdout/stderr重定向到文件中。python脚本正在远程计算机上运行。执行如下操作: stdin, stdout, stderr = ssh.exec_command(remotePath + proto) rc = stdout.channel.recv_exit_status() sys.stdout=open('erroLog', 'w') 如果您有权访问终端,请尝试使用shell重定向方法: $ python foo.py >

我是Python脚本编写的新手。正在尝试将stdout/stderr重定向到文件中。python脚本正在远程计算机上运行。执行如下操作:

stdin, stdout, stderr = ssh.exec_command(remotePath + proto)
rc = stdout.channel.recv_exit_status()
sys.stdout=open('erroLog', 'w')

如果您有权访问终端,请尝试使用shell重定向方法:

$ python foo.py > output.txt

粘贴的代码的最后一行是正确的,应该编写一个错误日志文件。可能服务器权限设置错误,脚本没有创建文件的写入权限?

假设将错误存储在变量中

output=open(erroLog, "w")
output.write (variable)