Advertisement
Guest User

Untitled

a guest
Sep 5th, 2011
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. к нему test.txt с любым текстом, который будем искать
  2.  
  3.  
  4. #!/usr/local/bin/python3
  5.  
  6. import sys, os, cgi, random, re
  7. sys.stdout.buffer.write(b'Content-type: text/html;charset=utf-8\n\n')
  8. os.dup2(1, 2)
  9.  
  10.  
  11. def _print(text):
  12.     sys.stdout.buffer.write(text.encode('utf8'))
  13.     sys.stdout.flush()
  14.  
  15. def execute(command, silent=True):
  16.     import subprocess
  17.  
  18.     device = open('/dev/null', 'w') if silent else None
  19.  
  20.     proc = subprocess.Popen(command, shell=True,
  21.             stdout=device, stderr=device).wait()
  22.  
  23.  
  24. form = cgi.FieldStorage()
  25.  
  26. _print('''
  27.     <form method='get'>
  28.     <input type='text' name='searchtext' size='5' />
  29.     </form><hr />
  30.     ''')
  31.  
  32. find = form.getvalue('searchtext') if 'searchtext' in form else ''
  33. _print('Ищем текст: <b>%s</b><br />\n' % find)
  34.  
  35. bash = "grep --binary-files=text \"%s\" test.txt" % find
  36. _print('command: %s<br />\n' % bash)
  37.  
  38. execute(bash, silent=False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement