本文介绍了wget与-r和-O一起挂起-的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是非常奇怪的wget行为.我使用的是Debian 7.2.

This is a VERY strange wget behavior. I'm on debian 7.2.

wget -r -O - www.blankwebsite.com

永远挂起.我是说挂起,它不是通过互联网搜索的,我可以用strace进行验证.如果我这样做:

hangs forever. And I mean it hangs, it isn't searching through the internet,I can verify it with a strace.If I do this:

while read R
do
   wget -r -O - www.blankwebsite.com
done < smallfile

smallfile包含一行,命令将在几秒钟后退出.

with smallfile containing a single line, the command exits in a few seconds.

我也尝试过

wget -r -O - localhost/test.html

和一个空的test.html文件,结果相同.对我来说,这听起来像是个错误.
一切都很好用-O myfile更改-O -或删除-r.
我使用-O -是因为我将输出传递给grep.
谁能解释一下?你看到类似的东西了吗?

with an empty test.html file, same results. To me, it sounds like a bug.
Everything runs fine changing -O - with -O myfile or removing -r.
I used -O - because I was passing output to grep.
Could anyone explain that? Have you seen anything similar?

推荐答案

当然:

 wget -r -O file www.blankwebsite.com

可以,但是BUG是这样的:

works, but the BUG is that:

 wget -r -O - www.blankwebsite.com

挂起!

同样的问题是,如果您创建FIFO

The same problem is if you create a FIFO

mkfifo /tmp/myfifo
wget -r -O /tmp/myfifo www.blankwebsite.com

使用-r选项调用

wget时,它将尝试找到读取输出文件的HTML"a href = ..."标记.由于输出文件是FIFO或stdout(例如HYPHEN char'-'),因此无法找到任何标签并等待INPUT.然后,在读取系统调用上,您将永远拥有一个wget进程waintg.

wget, when called with -r option, will try to find HTML "a href=..." tags reading the output file. Since the output file is a FIFO or stdout (ex. HYPHEN char '-') it is not able to find any tag and waits for INPUT. Then you will have a wget process waintg forever on a read system call.

要解决此问题,您可以:1)修补wget来处理这种情况2)修补wget不允许使用"-r -O-"组合...(只需检查"-O"的参数是否为常规文件)3)使用类似的解决方法:

To resolve this you can:1) Patch wget to handle this case2) Patch wget to not allow "-r -O -" combination... (Just check that the argument of '-O' is a regular file)3) Use a workaround like:

TMPFILE=$(mktemp /tmp/wget.XXXXXX)
wget -r -O $TMPFILE www.blankwebsite.com
grep STRING $TMPFILE
rm $TMPFILE

这篇关于wget与-r和-O一起挂起-的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 07:28