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
这是我的程序,这里我需要向我的应用程序发送文本,应用程序的输出写在一个名为 output.txt 的文件中,但是应用程序需要一些时间,具体取决于输入的大小,问题是这条语句output_file=open("/var/www/cgi-bin/output.txt", "r").read()
正在读取输出.txt 在应用程序将新数据写入文件之前。我希望 output_file 应该等到应用程序完成执行并应该从 output.txt 中获取更新的数据。
我尝试了很多但无法弄清楚,请帮助我解决这个问题:)
谢谢 :)