[Tutor] Subprocess Stdout Redirection

Gil Johnson x7-g5W_rt at earthlink.net
Mon Feb 8 03:45:32 CET 2010


Muhammad,
I am no expert, but I think you have to call proc_log.close() in your
StartProc() to make sure that the file is written out to disk.
If I understand what you are doing, you are trying to generate a new path for
each pass through the loop, of the form 0/, 1/,... and write "MyLog.txt" to the
new directory.
When I did something like this in the past I put the files MyLog0.txt,
MyLog1.txt, MyLog2.txt,... in a single directory, which was simpler and more
convenient for me when I gathered the information together for analysis:

def NewProc(FileNum):
     filename = "MyLog" + repr(FileNum) + ".txt"
     proc_log = open(filename,"w")
     proc_log.write("Output here")
     proc_log.close()
     return

for i in range(0, 5):
    NewProc(i)




More information about the Tutor mailing list