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 6709089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:50:19+00:00 2026-05-26T07:50:19+00:00

I have a problem concerning the reading of the stdout in python. I have

  • 0

I have a problem concerning the reading of the stdout in python. I have to explain a bit what I am trying to do.

I have a Python program (foo); this calls a second python program (bar). bar will give back to stdout status details and other information to be logged. The foo now has to read this. In principle it works. I can grab the output of bar and send it to a log file without any problems. The problems start when I try to look for certain phrases in the output from bar (the status report).

I am reading the output with os.read(fn, n) from the stdout of bar. The problem is that os.read reads n bytes, but not a line; it can be more or less. I want it to read every line that is written to stdout by bar, these lines end with \n and are written either with print or with sys.stdout.write followed by a sys.stdout.flush().

foo calls bar using:

bar= subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
fd_in[0] = bar.stdout.fileno()
fd_in[1] = bar.stderr.fileno()

My code looks like this at the moment. bar writes:

print 'TAG INFO1 INFO2 INFO3'
#or
sys.stdout.write('TAG INFO1 INFO2 INFO3\n')
sys.stdout.flush()

I am reading in foo with

buf = os.read(fd_in[0], 256)

When I write this to a log file with:

int_logFile.write(buf)
int_logFile.flush()

everything is fine. But if I want to grab the first word of the output line like this:

tokens = buf.strip('\n').split(' ')

I end up in missery, because I do not get TAG, but I might have INFOx or something from a previous output nothing to do with my status messages.

So to sum it up I need to read the output of bar line by line in foo. Any 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-26T07:50:20+00:00Added an answer on May 26, 2026 at 7:50 am

    Er, bar.stdout.readline()? Going all the way to file descriptors is rarely necessary.

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

Sidebar

Related Questions

I have problem concerning python packages and testing. I'm writing an application using wx
I am using LaTeX and I have a problem concerning string manipulation. I want
I have quite a problem concerning the use of relational database concepts in Delphi
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I seem to have the all-familiar problem of correctly reading and viewing a web
I have a problem concerning nested templates and the overriding of the assignment operator.
i have a problem with reading from a file, and converting content to double.
I have a weird problem concerning mysql timezone. In my website config file i
I have problem concerning translations in qt. All translations in my porject work fine,
I have a little problem concerning databinding, infact I have a WPF project where

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.