【发布时间】:2013-12-05 07:01:59
【问题描述】:
我刚刚发现了这个很棒的 wget 包装器,我想使用 subprocess 模块将它重写为 python 脚本。然而,给我各种各样的错误结果是相当棘手的。
download()
{
local url=$1
echo -n " "
wget --progress=dot $url 2>&1 | grep --line-buffered "%" | \
sed -u -e "s,\.,,g" | awk '{printf("\b\b\b\b%4s", $2)}'
echo -ne "\b\b\b\b"
echo " DONE"
}
那么可以这样调用:
file="patch-2.6.37.gz"
echo -n "Downloading $file:"
download "http://www.kernel.org/pub/linux/kernel/v2.6/$file"
有什么想法吗?
来源:http://fitnr.com/showing-file-download-progress-using-wget.html
【问题讨论】:
-
您需要了解我们在 Python 中的尝试,以便我们能够为您提供帮助。
-
基本上还没有..!我目前迷失在子流程文档中..!理想的做法是对提议的解决方案进行有见地的解释,以便我能够正确掌握子流程模块的概念并对其进行扩展。
-
好吧,到目前为止我做到了:
wgetExecutable = '/usr/bin/wget' grepExecutable = '/usr/grep' wgetParameters = ['--progress=dot', "link_to_file"] grepParameters = ['--line-buffered', "%"] wgetPopen = subprocess.Popen([wgetExecutable] + wgetParameters, stdout=subprocess.PIPE) -
grepPopen = subprocess.Popen([grepExecutable] + grepParameters, stdin=wgetPopen.stdout)但是我在stdin=wgetPopen.stdout收到错误 OSError: [Errno 2] No such file or directory -
请注意,还有一个
sh模块(具有该名称)可以处理 bash 和 python 之间的桥梁!
标签: python bash shell subprocess wrapper