import cgi
def fill():
s = """\
<html><body>
<form method="get" action="./show">
<p>Type a word: <input type="text" name="word">
<input type="submit" value="Submit"</p>
</form></body></html>
"""
return s
# Receive the Request object
def show(req):
# The getfirst() method returns the value of the first field with the
# name passed as the method argument
word = req.form.getfirst('word', '')
print "Creating a text file with the write() method."
text_file = open("/var/www/cgi-bin/input.txt", "w")
text_file.write(word)
text_file.close()
# Escape the user input to avoid script injection attacks
#word = cgi.escape(word)
'''Input triggers the application to start its process'''
output_file=open("/var/www/cgi-bin/output.txt", "r").read()
s = """\
<html><body>
<p>The submitted word was "%s"</p>
<p><a href="./fill">Submit another word!</a></p>
</body></html>
"""
return s % output_file
This is my program, here i need to send text to my application and output of the application is written on a file called output.txt, But the application takes some time depending upon the size of the input, problem is this statement output_file=open("/var/www/cgi-bin/output.txt", "r").read()
is reading output.txt before the application writes new data over the file. I want that output_file should wait till the application finishes execution and should take updated data from output.txt.
I tried a lot but couldn't figure out, Please help me out through this :)
Thank you :)