title: python os.system error: "global name 'output' is not defined"
body: <p>Newbie here.  any help would be appreciated..  </p>
  
  <p>I am writing a cgi script that runs a tcp pcap diagnostic tool.  if I would run the command in bash it would look like:</p>
  
  <pre><code>/home/fsoft/cap/capnostic -r 38350 /home/fsoft/brad.pcap &gt; 38350
  </code></pre>
  
  <p>So I am trying to do it in python:</p>
  
  <pre><code>output = os.system('/home/fsoft/cap/capnostic -r' + port + directory+filename '&gt;' + jobdir+filename
  </code></pre>
  
  <p>I have a feeling the '>' is messing things up..  But I can't seem to find the right syntax..  Also once I get the command correctly will I just be able to print the output variable?</p>
  
  <pre><code> print '%s' % (output)
  </code></pre>
  
  <p>the output may be 3 pages of data..</p>
  
  <p>Thanks for the help.</p>
  
  <p>Here is my full code:</p>
  
  <pre><code>#!/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 &gt; %s%s' % (port, directory,     filename, jobdir, filename))
  capout()
  
  def htmlout():
   print 'Content-type: text/html\n'
   print '&lt;html&gt;'
   print '&lt;head&gt;'
   print '&lt;title&gt;Capnostic Output&lt;/title&gt;'
   print '&lt;/head&gt;'
   print '&lt;body&gt;'
   print '&lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;center&gt;'
   print '&lt;table border=0&gt;'
   print '&lt;TR&gt;'
   print '&lt;TD&gt;&lt;center&gt;port = %s&lt;BR&gt;filename = %s&lt;BR&gt;Directory = %s&lt;BR&gt;Job Directory = %s&lt;/TD&gt;' % (port,filename,directory,jobdir)
   print '&lt;/TR&gt;'
   print '&lt;/table&gt;'
   print '&lt;BR&gt;&lt;BR&gt;&lt;BR&gt;'
   print '%s' % (output)
   print '&lt;/body&gt;'
   print '&lt;/html&gt;'
  
  htmlout()
  </code></pre>
  
  <p>It is now telling me:</p>
  
  <pre><code>&lt;type 'exceptions.NameError'&gt;: global name 'output' is not defined 
    args = ("global name 'output' is not defined",) 
    message = "global name 'output' is not defined"
  </code></pre>