问题描述
使用-T和-t运行相同的ssh命令时,任何stderr输出都分别到达stderr vs.stdout.
When running the same ssh command with -T and -t, any stderr output arrives on stderr vs. stdout, respectively.
未分配pty:ssh -T user@host "echo >&2 foo" 1>/tmp/out 2>/tmp/err
输出被写入/tmp/err
.
分配了pty:ssh -t user@host "echo >&2 foo" 1>/tmp/out 2>/tmp/err
现在将输出写入/tmp/out
.
我有点理解,使用pty可以模拟完整的伪屏幕,并且输出处于原始模式.发送到屏幕的输出然后通过stdout发送回ssh,并且ssh的tty也设置为原始模式.有人可以进一步解释吗?
I somewhat understand that with pty a full pseudo screen is simulated and that the output is in raw mode. The output sent to the screen then are sent via stdout back to ssh and ssh's tty is also set to raw mode. Can somebody please explain it further?
推荐答案
一个tty没有单独的输出和错误通道.只有一个输出通道.只需将其写入CRT,串行端口,终端窗口,调制解调器,打印机或与tty连接的任何内容即可.
A tty does not have separate output and error channels. There is only one output channel; whatever you write to it simply goes to the CRT, serial port, terminal window, modem, printer, or whatever is connected to the tty.
为运行命令分配tty时,理论上ssh
可以将命令的stdin和stdout附加到tty,相反,将命令的stderr附加到与stdrr通道(管道)完全分开的单独stderr通道(管道)蒂但是,这与在tty上运行的命令应将其所有3个stdio通道都连接到同一tty的约定不一致,并且某些命令可能会混淆或表现不同.因此ssh
选择遵循约定.
When allocating a tty for running a command, ssh
could in theory attach the command's stdin and stdout to the tty, while in contrast attaching the command's stderr to a separate stderr channel (a pipe) that is completely separate from the tty. However, this does not agree with the convention that a command running on a tty should have all 3 of its stdio channels connected to that same tty, and some commands might be confused or behave differently. So ssh
chooses to follow convention.
不是使用tty时,ssh
可以将命令的stdin,stdout和stderr附加到3个单独的单向管道.
When not using a tty, ssh
is free to attach the command's stdin, stdout, and stderr to 3 separate unidirectional pipes.
这篇关于为什么OpenSSH RequestTTY导致stderr重定向到stdout?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!