为什么aws --version写入stderr?

时间:2017-04-07 14:11:36

标签: amazon-web-services amazon-ec2 aws-cli

为什么标准检查aws --version会将预期输出打印到stderr,而不是stdout?

$ aws --version 2>err.log
$ cat err.log
aws-cli/1.11.65 Python/2.7.13 Darwin/16.5.0 botocore/1.5.28
$ aws --version > out.log
aws-cli/1.11.65 Python/2.7.13 Darwin/16.5.0 botocore/1.5.28
$ cat out.log
$

如果命令成功完成,将结果写入stdout是有意义的。其他命令如aws ec2 describe-imagesaws ec2 describe-instances正确地将输出写入标准输出。

检查CentOS和MacOS。

1 个答案:

答案 0 :(得分:7)

这是由Python 3.4中修复的bug in argparse引起的。

awscli是用Python编写的,它使用argparse module来解析命令行。它还使用argparse的action="version" feature来简化版本打印。这将在Python 3.4之前将版本字符串打印到stderr,并在Python 3.4 +中打印到stdout。