Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Io 为什么有些程序在stderr上编写而不是在stdout上输出?_Io_Stdout_Stderr - Fatal编程技术网

Io 为什么有些程序在stderr上编写而不是在stdout上输出?

Io 为什么有些程序在stderr上编写而不是在stdout上输出?,io,stdout,stderr,Io,Stdout,Stderr,我最近在.bashrc文件中添加了一个ssh add命令。我发现 ssh添加$HOME/.ssh/id\u rsa\u github>/dev/null 每次打开shell时,都会显示消息“添加了标识和其他内容”的结果 当 ssh添加$HOME/.ssh/id\u rsa\u github>/dev/null 2>&1 玩了这个把戏,我的壳现在“干净了” 在网上阅读时,我发现其他命令也能做到这一点(例如time)。您能解释一下为什么会这样做吗?当您将输出从一个进程重定向到另一个进程时,例如通过管

我最近在.bashrc文件中添加了一个ssh add命令。我发现

ssh添加$HOME/.ssh/id\u rsa\u github>/dev/null

每次打开shell时,都会显示消息“添加了标识和其他内容”的结果

ssh添加$HOME/.ssh/id\u rsa\u github>/dev/null 2>&1

玩了这个把戏,我的壳现在“干净了”


在网上阅读时,我发现其他命令也能做到这一点(例如
time
)。您能解释一下为什么会这样做吗?

当您将输出从一个进程重定向到另一个进程时,例如通过管道

$ procA | procB | procC
这通常是使用标准输出完成的。我希望
time
和类似的命令输出到stderr,以避免损坏这个流。如果您在使用时间,那么您就是在诊断问题,您不希望无意中向下游流程提供额外的输入

包括一些进一步的细节和一些历史