Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6541007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:03:02+00:00 2026-05-25T11:03:02+00:00

one of my function in the program checks the md5sum of hashfile def check():

  • 0

one of my function in the program checks the md5sum of hashfile

def check():
    print "checking integrity status.."
    md5 = subprocess.Popen(["md5sum", "-c", hashfile],shell=False, stdout=subprocess.PIPE)
    #fopen = open(basefile, "r")
    for f in md5.stdout.readlines():
        fc = f.rstrip("\n")
        sys.stdout.write("\rChecking..." + fc)
        sys.stdout.flush()

now what happens is that the whole command is first executed and then for loop reads from md5 using md5.stdout.readlines, as such it is not dynamic i.e. i dont get the output as the command is executed….is there a way i can get the output while the command is in execution…

fixed using glglgl’s 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()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:03:04+00:00Added an answer on May 25, 2026 at 11:03 am

    Of course. There are several ways.

    1. First, you could work with md5.stdout.read(), but there you would have to do line separation by yourself.

    2. Then, you could operate with the file object md5.stdout as iterator. But there seems to be an issue with buffering, i. e. you don’t get the results immediately.

    3. And then there is a possibility to call md5.stdout.readline() repeatedly until it returns ''.

    The third way is to be preferred in this case; I would suggest it to do like this:

    …

    for f in iter(md5.stdout.readline, ''):
        fc = f.rstrip("\n")
        sys.stdout.write("\rChecked " + fc)
        sys.stdout.flush()
    

    I have also changed the output text, as there is only an output if che check is done already.

    If that is not what you want, but rather really haveing every output captured separately, you should switch to point 1. But that makes it more complicated. I will think about a solution on indication that it is wanted.

    There, one must consider the following points:

    • read() blocks, so one should read byte for byte (quite ugly).
    • There is the question what should be output and when should there be a intermitting output.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

User Defined Function (UDFs) are functions that one can program and can be dynamically
I've got one function checkEvery15Seconds that runs every 15 seconds. It checks to see
Hi I have a program written in C++ in which one or two functions
In one of the C++ programs, I saw a function prototype : int Classifier::command(int
I have two begininer programs, both using the 'while' function, one works correctly, and
i am created one function to upload image with random name and it worked
I have one function for one element: <a href=javascript:void(0); onclick=dothis()>Link</a> When this function is
I have made one function in which I am passing a matrix and returning
I have one function ParseHtmlTable(string htmlContent) . Now in that function I want to
I had only one function to Add another row to the table id=tblOtherParties and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.