I am having a service which run using a batch file in command prompt, I want to read the whole information running in the console and want to write it to an another file but I am able to write it only when the service is closed completely.
I am running the service as a process in python and I am able to read the content of the service but I am able to write the content only when the complete service is run completely, as the service is an iterative process it would take 1 hr to complete but I want to be written it meanwhile the service is running......
Assuming the name of your service is service , you could try to run this program
import subprocess as sp
SERVICE_COMMAND = "service"
with open("output.txt", "w") as output_file:
process = sp.Popen(command, shell=True, stdout=sp.PIPE)
for line in process.stdout:
for f in (output_file, sys.stdout):
if __name__ == "__main__":