I have a python script that calls an executable. Executable output is redirected to the log file along with some information about the time it was called. For example, using python -Vas an executable file for illustration:
import time, subprocess
with open('./LOGFILE.txt', 'a') as F:
F.write('******\n')
F.write('Events on %s :\n'%time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
EXE_output = subprocess.call(['python', '-V'], stdout=F, stderr=F)
File output LOGFILE.txt:
Python 2.7.3
******
Events on 2013-04-10 19:27:25 :
Where did I expect this:
******
Events on 2013-04-10 19:27:25 :
Python 2.7.3
I wrote ******the time information in the opened log file before starting the subprocess and redirected its output and error to the file. Why so ordered? and how can i change the order?
source
share