这是一种非常奇怪的wget
行为。我正在使用debian 7.2。
wget -r -O - www.blankwebsite.com
永远挂起。我的意思是挂起,它不是通过互联网搜索,
我可以使用strace
验证它。
如果我这样做:
while read R
do
wget -r -O - www.blankwebsite.com
done < smallfile
smallfile
包含一行,该命令会在几秒钟后退出。
我也试过
wget -r -O - localhost/test.html
使用空test.html
文件,结果相同。对我来说,这听起来像个臭虫
一切正常,-O -
改为-O myfile
或移除-r
我使用-O -
因为我将输出传递给grep
谁能解释一下呢?你见过类似的吗?
答案 0 :(得分:7)
当然:
wget -r -O file www.blankwebsite.com
有效,但BUG是:
wget -r -O - www.blankwebsite.com
挂起!
同样的问题是如果你创建一个FIFO
mkfifo /tmp/myfifo
wget -r -O /tmp/myfifo www.blankwebsite.com
wget,当使用-r选项调用时,将尝试查找读取输出文件的HTML“a href = ...”标记。由于输出文件是FIFO或标准输出(例如HYPHEN char' - '),因此无法找到任何标记并等待INPUT。然后,在读取系统调用时,您将永远有一个wget进程waintg。
要解决此问题,您可以: 1)补丁wget来处理这种情况 2)修补wget不允许“-r -O - ”组合......(只需检查'-O'的参数是否是常规文件) 3)使用类似的解决方法:
TMPFILE=$(mktemp /tmp/wget.XXXXXX)
wget -r -O $TMPFILE www.blankwebsite.com
grep STRING $TMPFILE
rm $TMPFILE
答案 1 :(得分:0)
@tonjo:您能否尝试使用以下代码。
wget -r -O file www.blankwebsite.com
而不是使用
wget -r -O - www.blankwebsite.com
答案 2 :(得分:0)
如文件中所述:
Similarly, using '-r' or '-p' with '-O' may not work as you expect:
Wget won't just download the first file to FILE and then download
the rest to their normal names: _all_ downloaded content will be
placed in FILE. This was disabled in version 1.11, but has been
reinstated (with a warning) in 1.11.2, as there are some cases
where this behavior can actually have some use.
这是一个已知的问题,也是以某种方式下载的,使用-r和-O与不可搜索的文件无法使用wget将数据直接序列化到文件的方式。