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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:22:52+00:00 2026-05-28T15:22:52+00:00

Trying to redirect a subprocess’ output to a file. server.py: while 1: print Count

  • 0

Trying to redirect a subprocess’ output to a file.

server.py:

while 1:
    print "Count " + str(count)
    sys.stdout.flush()
    count = count + 1
    time.sleep(1)

Laucher:

cmd = './server.py >temp.txt'
args = shlex.split(cmd)
server = subprocess.Popen( args )

The output appear on screen, temp.txt remains empty.
What am I doing wrong?

As background I am trying to capture the output of a program that has already been written.

I cannot use:

server = subprocess.Popen(
                [exe_name],
                stdin=subprocess.PIPE, stdout=subprocess.PIPE)

as the program may not flush.
Instead I was going to redirect output through a fifo. This works fine if I manually launch server.py but obviously not if I Popen() cause redirect doesnt work.
ps -aux shows that server.py was launched correctly.

  • 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-28T15:22:53+00:00Added an answer on May 28, 2026 at 3:22 pm

    Altenatively, you can use the stdout parameter with a file object:

    with open('temp.txt', 'w') as output:
        server = subprocess.Popen('./server.py', stdout=output)
        server.communicate()
    

    As explained in the documentation:

    stdin, stdout and stderr specify the executed program’s standard input, standard output and standard error file handles, respectively. Valid values are PIPE, an existing file descriptor (a positive integer), an existing file object, and None.

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

Sidebar

Related Questions

I'm calling rtmpdump via subprocess and trying to redirect its output to a file.
I'm trying to redirect the java compiler output to a file. I thought it's
I'm trying to redirect all output (stdout + stderr) of a Windows command to
I'm trying to redirect the output from manage.py to a text file, but only
I'm trying to redirect some of the standard output to a text file, and
I am trying to redirect the output from my DLL to an external console
I am trying to redirect the Console output of a C#/Mono application into a
I'm trying to redirect an easy to remember url to a php file but
I am trying to redirect all traffic through index.php. Here is my .htaccess file:
Hi I am trying to redirect all links to any pdf file in my

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.