新手来了 任何帮助,将不胜感激..
我正在编写一个运行 tcp pcap 诊断工具的 cgi 脚本。如果我在 bash 中运行命令,它看起来像:
/home/fsoft/cap/capnostic -r 38350 /home/fsoft/brad.pcap > 38350
所以我试图在python中做到这一点:
output = os.system('/home/fsoft/cap/capnostic -r' + port + directory+filename '>' + jobdir+filename
我有一种感觉'>'把事情搞砸了..但我似乎找不到正确的语法..而且一旦我正确获得命令,我就能打印输出变量吗?
print '%s' % (output)
输出可能是3页数据..
谢谢您的帮助。
这是我的完整代码:
#!/usr/bin/env python
import cgi, os
import cgitb; cgitb.enable()
import subprocess
form = cgi.FieldStorage()
port = form.getvalue("port")
filename = form.getvalue("filename")
directory = form.getvalue("directory")
jobdir = '/var/www/jobs/' + filename
def createdir():
os.system('mkdir /var/www/jobs/' + filename)
createdir()
def capout():
output = os.system('/home/fsoft/cap/capnostic -r %s %s%s > %s%s' % (port, directory, filename, jobdir, filename))
capout()
def htmlout():
print 'Content-type: text/html\n'
print '<html>'
print '<head>'
print '<title>Capnostic Output</title>'
print '</head>'
print '<body>'
print '<BR><BR><BR><center>'
print '<table border=0>'
print '<TR>'
print '<TD><center>port = %s<BR>filename = %s<BR>Directory = %s<BR>Job Directory = %s</TD>' % (port,filename,directory,jobdir)
print '</TR>'
print '</table>'
print '<BR><BR><BR>'
print '%s' % (output)
print '</body>'
print '</html>'
htmlout()
它现在告诉我:
<type 'exceptions.NameError'>: global name 'output' is not defined
args = ("global name 'output' is not defined",)
message = "global name 'output' is not defined"