通过ssh流式传输远程执行程序的输出

rei*_*zor 3 python ssh

是否可以通过ssh传输正在执行的程序的输出?

示例程序(远程上的test.py):

import time
while True:
    print time.time()
    time.sleep(1)
Run Code Online (Sandbox Code Playgroud)

命令(本地):

ssh name@remote 'python test.py'
Run Code Online (Sandbox Code Playgroud)

由于该程序永远不会终止,因此不会流输出。这有可能吗?

rei*_*zor 5

显然,将-t选项添加到ssh命令即可。它刷新标准输出:

ssh -t name@remote 'python test.py'
Run Code Online (Sandbox Code Playgroud)