2017-04-07 70 views
1

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

$ 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 
$ 

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

检查CentOS和MacOS。

+0

这里的一些解释:http://stackoverflow.com/questions/13483443/why-does-java-version-go-to-stderr – helloV

回答

6

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

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