如果命令行“使用”在stdout或stderr上打印? [英] Should the command line "usage" be printed on stdout or stderr?

查看:248
本文介绍了如果命令行“使用”在stdout或stderr上打印?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

打印应用程序的用法时,是否应在stdout或stderr上完成?

When printing the "usage" of an application, should it be done on stdout or on stderr?

根据应用程序,我看到过几种情况,似乎没有一个规则。也许我错了,有一个好的做法。在这种情况下,它是什么?

Depending on the application I've seen several cases, but there doesn't seem to be one rule. Maybe I'm mistaken and there is one good practice. In that case, what is it?

推荐答案

从来没有想过,但为什么不写使用说明stderr如果程序被调用没有或错误的参数,并用 - help (或类似)参数调用时写入stdout?这样,如果由于错误显示使用,它会去stderr,如果它不是一个错误,因为用户请求它,它去stdout。似乎是逻辑的,不知何故。

Never thought about it, but why not write the usage instructions to stderr if the program was called with no or wrong arguments, and write it to stdout when called with a --help (or similar) argument? This way, if the usage is shown because of an error, it goes to stderr, and if it's not an error because the user requested it, it goes to stdout. Seems logical, somehow.

这篇关于如果命令行“使用”在stdout或stderr上打印?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆