我正在运行一个基于Python的CGI脚本,在浏览器中打印“dig”命令的输出有困难。我使用Idle运行同一个脚本,它可以工作。在
脚本如下:#!/usr/bin/python3.5
#================================================================
# Modules
import cgi
import subprocess
import re
#================================================================
# Create HTML page
form = cgi.FieldStorage()
regex_url = re.compile(r'(^https?:\/\/)(.*?)(\/.*)')
url = form.getvalue('url')
origin = form.getvalue('origin')
print ("Content-type:text/html\r\n\r\n")
print ("")
print ("
")print ("
Lookup Tool")print ("
")print ("
DNS lookup tool
")
print("
")print("
Full URL including http/s:
")print("
Leave empty:
")print("")
print("
")host = regex_url.search(url)
hostname = host.group(2)
print("Hostname is: " + hostname )
resolver = subprocess.Popen(['dig', hostname], stdout=subprocess.PIPE)
print(resolver.communication())
我希望看到挖掘的结果www.google.com但事实并非如此。但是,如果我执行“print(hostname)”,那么www.google.com会在网页上打印出来。在
我做错什么了