Форум сайта python.su
0
Правда теперь наблюдается другая проблема. Итак, есть пайтон 2.6.6
Есть скрипт веб-сервера:
import BaseHTTPServer import CGIHTTPServer port = 8080 addrport = ('', port) serv = BaseHTTPServer.HTTPServer( addrport, CGIHTTPServer.CGIHTTPRequestHandler ) serv.serve_forever() print('Server is working. Kill the PID if not needed anymore')
<html> <head> <meta http-equiv='Content-Type' content='text/html; charset=utf-8'> <title>Interactive Page</title> </head> <body> <form method=POST action="/cgi-bin/reply.py"> <P><B>Enter your name:</B> <P><input type=text name=user> <P><input type=submit> </form> <form method=POST action="/cgi-bin/show_users.py"> <P><B>Click me, if u want all schemas</B> <P><input type=submit> </form> </body> </html>
import os os.system('/opt/oracle/web2/cgi-bin/show_users.sh > /opt/oracle/web2/test_text.html') doc = """ <html> <head> <meta http-equiv='Content-Type' content='text/html; charset=utf-8'> <title>The job is done!</title> </head> <body> Please open http://172.17.2.34:8080/test_text.html </body> </html> """ print(doc) f_out = r'<html><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <title>One long row</title><body><table width="100%" cellspacing="0" cellpadding="5">' with open(r'/opt/oracle/web2/test_text.html', 'r') as f: for i in f.readlines(): f_out += '<tr><td width="500" valign="top">' + i + '</td></tr>' f_out += '</table></body></html>' with open(r'/opt/oracle/web2/test_text.html', 'w') as f: f.write(f_out)
my-ibm-w.oilspace.net - - [21/Jul/2014 10:17:22] "POST /cgi-bin/show_users.py HTTP/1.1" 200 - Traceback (most recent call last): File "/usr/lib64/python2.6/CGIHTTPServer.py", line 248, in run_cgi os.execve(scriptfile, args, os.environ) OSError: [Errno 8] Exec format error
Офлайн
0
При этом сам show_users.py из ОС вызывается без проблем
Офлайн
857
thomasOSError: [Errno 8] Exec format error
#!/usr/bin/env python # coding: utf-8
Офлайн
0
py.user.next
только только это добавил и заработало 
Офлайн
0
Всем привет еще раз!
Мне теперь осталось сделать последнюю хитрость, и то что человек вбивает в текстбокс хтмл загнать в качестве переменной в питон и эту переменную передать в os.system.
Хтмлная страничка находится выше, а вот скрипт, который будет вызываться, я представляю такой:
#!/usr/bin/env pyton import cgi user = cgi.FieldStorage() doc_yes = """ <html> <head> <meta http-equiv='Content-Type' content='text/html; charset=utf-8'> <title>The job is done!</title> </head> <body> User has been created. You can use it now, the password is default </body> </html> """ doc_no = """ <html> <head> <meta http-equiv='Content-Type' content='text/html; charset=utf-8'> <title>Error!</title> </head> <body> User has been not created! did you fill user text form? </body> </html> """ if 'user' in user: user = cgi.escape(user['user'].value) os.system('/opt/oracle/web2/cgi-bin/create_user.sh $user') print(doc_yes) else: print(doc_no)
os.system('/opt/oracle/web2/cgi-bin/create_user.sh $user')
Отредактировано thomas (Июль 22, 2014 10:08:12)
Офлайн
857
>>> user = 'x' >>> '/opt/oracle/web2/cgi-bin/create_user.sh {}'.format(user) '/opt/oracle/web2/cgi-bin/create_user.sh x' >>>
Офлайн
0
py.user.next
Работает, спасибо!
Офлайн