def wget_url(url):
try:
wget = subprocess.Popen(["wget "+url],shell=True,stdout=PIPE,stderr=PIPE)
return wget
except:
print("HTTP error")
a=wget_url(url)
a.stdout.readlines() #return an empty string.
a.stderr.readlines() #return the normal output that would be displayed in terminal
这是正常的吗?为什么stdout什么都不返回?
答案 0 :(得分:0)
这不是Python问题,而是wget
的一个特性:
wget url > stdout.txt 2> stderr.txt
此处stdout.txt
为空,stdout.txt 2>
的屏幕输出为200 OK
等。这是well known fact。
诊断消息可能会干扰管道,因此最好路由到stderr。