2017-04-07 38 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。

相關問題