Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- к нему test.txt с любым текстом, который будем искать
- #!/usr/local/bin/python3
- import sys, os, cgi, random, re
- sys.stdout.buffer.write(b'Content-type: text/html;charset=utf-8\n\n')
- os.dup2(1, 2)
- def _print(text):
- sys.stdout.buffer.write(text.encode('utf8'))
- sys.stdout.flush()
- def execute(command, silent=True):
- import subprocess
- device = open('/dev/null', 'w') if silent else None
- proc = subprocess.Popen(command, shell=True,
- stdout=device, stderr=device).wait()
- form = cgi.FieldStorage()
- _print('''
- <form method='get'>
- <input type='text' name='searchtext' size='5' />
- </form><hr />
- ''')
- find = form.getvalue('searchtext') if 'searchtext' in form else ''
- _print('Ищем текст: <b>%s</b><br />\n' % find)
- bash = "grep --binary-files=text \"%s\" test.txt" % find
- _print('command: %s<br />\n' % bash)
- execute(bash, silent=False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement