【问题标题】:wget gets not expecting exit codewget 不期望退出代码
【发布时间】:2020-01-23 18:10:23
【问题描述】:

我在 bash 脚本中使用 wget 并检查退出代码以打印一些消息。我就是这样做的:

wget -U mozilla -O my_page.html https://example.com/page
echo $?

有时我会成功获取页面,因为它存在,有时我会得到一个无效文件,因为 404 错误(页面不存在)。

嗯,我总是得到退出代码号4,在任何情况下。

wget 的手册页说明了 wget 退出代码:

0   No problems occurred.
1   Generic error code.
2   Parse error---for instance, when parsing command-line options, the .wgetrc or .netrc...
3   File I/O error.
4   Network failure.
5   SSL verification failure.
6   Username/password authentication failure.
7   Protocol errors.
8   Server issued an error response.

我希望在成功下载时获得代码 0,在收到 404 错误时获得代码 8

发生了什么事?

【问题讨论】:

    标签: bash shell wget exit-code


    【解决方案1】:

    我检查了你的命令(稍作修改),对我来说它工作正常。

    wget -U mozilla -O test.html https://google.com/ >>/dev/null 2>&1; echo $?
    0  
    

    当尝试不存在的页面时

    wget -U mozilla -O test.html https://google.com/test >>/dev/null 2>&1; echo $?
    8
    

    也许您尝试测试的网站确实有问题?

    【讨论】:

    • 感谢您的测试。我认为这是我使用的一些参数的 wget 内部问题
    • 你使用的参数是什么?我也没有看到 Wget 的退出代码有任何此类问题。
    猜你喜欢
    • 2019-10-18
    • 1970-01-01
    • 1970-01-01
    • 2011-12-30
    • 1970-01-01
    • 2012-11-06
    • 2011-08-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多