one of my functions in the program checks the md5sum file hash
def check(): print "checking integrity status.." md5 = subprocess.Popen(["md5sum", "-c", hashfile],shell=False, stdout=subprocess.PIPE)
Now it happens that the whole command is executed first, and then to read the loop from md5 using md5.stdout.readlines, therefore it is not dynamic, i.e. I don't get output as the command executes .... there is a way I can get the output while the command is executing ...
fixed using glglgl answer:
def check(): print "checking integrity status.." md5 = subprocess.Popen(["md5sum", "-c", hashfile],shell=False, stdout=subprocess.PIPE) #fopen = open(basefile, "r") fc = "NULL" i = 0 for f in iter(md5.stdout.readline, ''): k = fc fc = f.rstrip("\n") if "FAILED" in fc: print fc i = i + 1 sys.stdout.write("\rChecking... "+ str(i)+ " " + fc + (' ' * (len(k) - len(fc))) ) sys.stdout.flush()
source share