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

  • Home
  • SEARCH
  • 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 5979999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:44:22+00:00 2026-05-22T21:44:22+00:00

I am using subprocess module for running commands from another app I know that

  • 0

I am using subprocess module for running commands from another app I know that you are able to do the following

import subprocess

app = subprocess(args, stdout=subprocess.PIPE)
out, err = app.communicate()
print out

I would like the output to be displayed as it happening as supposed to one big blob at the end. Ideas?

  • 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-22T21:44:23+00:00Added an answer on May 22, 2026 at 9:44 pm

    The problem may be that the command you are running in the subprocess buffers its output: in which case, in Blender’s answer, the process.stdout.read(1) would not return until the output buffer of the subprocess filled up, causing it to be flushed, and thus seen by the parent process.

    See this answer and this one for more information about how buffering affects things.

    Here’s some scripts to illustrate:

    # spew.py
    import sys
    import time
    
    for i in range(10):
        print 'Message no. %d' % i
        #sys.stdout.flush()
        time.sleep(1)
    

    and

    # runspew.py
    import subprocess
    import time
    
    start = time.time()
    p = subprocess.Popen(['python', 'spew.py'], stdout=subprocess.PIPE)
    data = p.stdout.read(1)
    print 'Elapsed time to first byte read: %.2f' % (time.time() - start)
    data = p.stdout.read()
    print 'Elapsed time to last byte read: %.2f' % (time.time() - start)
    p.wait()
    

    Now, put both scripts in the same directory and run python runspew.py. You’ll see something like this:

    Elapsed time to first byte read: 10.05
    Elapsed time to last byte read: 10.05
    

    Now, remove the comment from sys.stdout.flush() in spew.py and do python runspew.py again. You’ll now see something like this:

    Elapsed time to first byte read: 0.02
    Elapsed time to last byte read: 10.04
    

    Notice that runspew.py didn’t change: only the program which was run as the subprocess did. If the program you’re running can’t be made to run unbuffered (or flush frequently), then you’ll have to use expect/unbuffer as described in the other answers I linked to.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having problems redirecting stdio of another program using subprocess module. Just reading from
I have some commands which I am running using the subprocess module. I then
How do I execute the following shell command using the Python subprocess module? echo
I am trying to write a small app that uses the subprocess module. My
First let me say that I know it's better to use the subprocess module,
I'm trying to execute a series of commands using Pythons subprocess module, however I
From within a python script (main.py), I am using the subprocess module to run
The following is a python code using the subprocess module. Can someone explain what
I am using subprocess.check_output from pythons subprocess module to execute a ping command. Here
I have a python based tkinter script which executes some commands using subprocess module.

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.