开发者

How to wait until stdout has finished writing to file

Im trying to wait for stdout to finish writing to file. Does anyone have any ideas on how I can do this?

Heres the piece of code:

Code: Select all

session = open("c:\\sessionID.txt", "w")

#Execute previous exe and output session to text file from the current directory
cmd = os.path.realpath(os.getcwd()) +"\\Program.exe"

cmd = [os.getcwd() + '\\AOSLaunch.exe']

Execute the cmd which executes the program.exe and the output is saved to the sessionID.txt file
process = subprocess.Popen(cmd, stdout=session)
session.close()

So here the issue is that the time it takes for the program.exe to fire up and save the output to stdout can take time and sometimes the sessionID.txt file is empty as it takes too long. Here I want to make sure the sessionID.txt has been written to by the stdout.

Any help i开发者_开发百科s greatly appreciated. Many thanks TMARZI


Use the process.wait() (as explained in the Popen documentation) method after starting it, and it will wait the end of the execution....

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜