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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:54:01+00:00 2026-05-31T07:54:01+00:00

I have a simply script which print some message to the console, #!/usr/bin/python import

  • 0

I have a simply script which print some message to the console,

#!/usr/bin/python
import sys
print >>sys.stdout, "1 stdout"
print >>sys.stderr, "2 stderr"

normal sequence,

[dyno@cola:codes]$ ./x.py
1 stdout
2 stderr

[dyno@cola:codes]$ ./x.py 2>&1
1 stdout
2 stderr

wrong order in output,

[dyno@cola:codes]$ ./x.py &>x.txt
[dyno@cola:codes]$ cat x.txt
2 stderr
1 stdout
[dyno@cola:codes]$ ./x.py 2>&1 | tee x.log
2 stderr
1 stdout

It seems that adding sys.stdout.flush() can solve the problem, is there a way to force the message sequence (to redirect the output/error to a file) without changing the script?

  • 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-31T07:54:02+00:00Added an answer on May 31, 2026 at 7:54 am

    You can run python with the -u flag to force stdin, stdout, and stderr to be unbuffered. There is a performance penalty for doing so. It’s better to do explicit .flush() operations at any point that you intend everything to be “visible immediately”, both because it’s more efficient, and because it makes your intent obvious (“this should be visible immediately!”).

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

Sidebar

Related Questions

I have a simple test bash script which looks like that: #!/bin/bash cmd=rsync -rv
I have a very simple python script that should scan a text file, which
I have a bash script that simply calls different calls and redirect stdout and
I have written this short script (which I've stripped away some minor detail for
I have a python script which I call using python main.py on my terminal.
I have a simple script which is used to start another program. This other
I have a simple Perl script which runs as a Linux daemon using an
so i have ruby script that simply writes to a test.txt file with hello
I have a simple script that does some search and replace. This is basically
I have a simple Python script that I want to stop executing if a

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.