wget 输出和错误为标准 output/standard 错误

wget output & error to standard output/standard error

我想 运行 一个简单的 wget 来在终端上显示 return REST 调用,避免冗长乏味的输出。我正在使用:

$ wget -qO- localhost:8080/product/4
{"id":4,"name":"Spoon","price":2}
$

很好。但是,如果出现错误(例如 404 - NOT FOUND),它不会显示任何内容:

$ wget -qO- localhost:8080/badurl/4
$                <- nothing shown...

是否可以告诉 wget 在发生错误时显示错误?类似于:

$ wget -qO- localhost:8080/badurl/4
404 - HTTP NOT FOUND
$

也许我要求太多了,但问也无妨。

man wget:

-nv
--no-verbose
Turn off verbose without being completely quiet (use -q for that), which means that error messages and basic information still get printed.

例如:

$ wget -nv -O- google.com/doesnotexist
http://google.com/doesnotexist:
2020-09-28 19:57:38 ERROR 404: Not Found.