【发布时间】:2020-04-28 10:46:39
【问题描述】:
我们使用带有backticks的perl命令来执行curl,它会显示如下的进度条:
root@wetraveller:~# perl -e "print `curl http://127.0.0.1:53424/`"
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (7) Failed to connect to 127.0.0.1 port 53424: Connection refused
当我直接执行curl时,它不显示进度条:
root@wetraveller:~# curl http://127.0.0.1:53424/
curl: (7) Failed to connect to 127.0.0.1 port 53424: Connection refused
当我使用system命令执行curl时,没有显示进度条
root@wetraveller:~# perl -e "system('curl http://127.0.0.1:53424/')"
curl: (7) Failed to connect to 127.0.0.1 port 53424: Connection refused
正在执行完全相同的命令,但如果封装在反引号中并由 Perl 执行,则输出不同。
那么这是 Perl 还是 Curl 的问题?
我知道使用 -s 选项我们可以抑制输出,我只是好奇为什么输出会不同?
【问题讨论】:
-
问题是
curl。无论出于何种原因,当 stdout 不是 tty 时,curl 决定将横幅发送到 stderr。 -
感谢威廉的回答!我也想过,所以我这样测试:curl 127.0.0.1:2424 2>./error,但是没有进度条错误内容是一样的。
-
也许你有一个屏蔽 curl 的 shell 函数。
command curl ... 2> error有什么好处