Skip to content Skip to sidebar Skip to footer

Python Subprocess Executed Script Wont Write To File

I have written two scripts where one script calls subprocess.Popen to run a terminal command to execute the second script. After waiting 5 seconds, it will terminate the subprocess

Solution 1:

Use a context on the opening of the file, and add a flush right before you sleep:

withopen(filename, 'w') as f:
    ...
    while 1:
        *poll register*
        f.write(fp0)
        f.flush()
        sleep(1)

Solution 2:

Since you are terminating the sub-process maybe it is not flushing the output to the file. Try calling f.flush() to make sure the output is written to file.

Post a Comment for "Python Subprocess Executed Script Wont Write To File"