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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:11:25+00:00 2026-06-05T17:11:25+00:00

Since input and raw_input() stop the program from running anymore, I want to use

  • 0

Since input and raw_input() stop the program from running anymore, I want to use a subprocess to run this program…

while True: print raw_input()

and get its output.

This is what I have as my reading program:

import subprocess
process = subprocess.Popen('python subinput.py', stdout=subprocess.PIPE, stderr=subprocess.PIPE) 
while True:
    output=process.stdout.read(12)
    if output=='' and process.poll()!=None:
        break
    if output!='':
        sys.stdout.write(output)
        sys.stdout.flush()

When I run this, the subprocess exits almost as fast as it started. How can I fix this?

  • 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-06-05T17:11:27+00:00Added an answer on June 5, 2026 at 5:11 pm

    I’m afraid it won’t work this way.

    You assume, that subprocess will attach your console (your special
    case of stdin). This does not work, the module only has two
    options for specifying that: PIPE and STDOUT.

    When nothing is specified, the subprocess won’t be able to use
    the corresponding stream – it’s output will go nowhere or it will
    receive no input. The raw_input() ends because of EOF.

    The way to go is to have your input in the “main” program,
    and the work done in a subprocess.

    EDIT:

    Here’s an example in multiprocessing

    from multiprocessing import Process, Pipe
    import time
    
    def child(conn):
        while True:
            print "Processing..."
            time.sleep(1)
            if conn.poll(0):
                output = conn.recv()
                print output
            else:
                print "I got nothing this time"
    
    def parent():
        parent_conn, child_conn = Pipe()
        p = Process(target=child, args=(child_conn,))
        p.start()
        while True:
            data = raw_input()
            parent_conn.send(data)
        # p.join() - you have to find some way to stop all this...
        # like a specific message to quit etc.
    
    
    if __name__ == '__main__':
        parent()
    

    You of course need to make it more robust by finding a way too stop
    this cooperation. In my example both processes are in the same file,
    but you may organize it differently.

    This example works on Linux, you may have some problems with pipes on Windows,
    but it should be altogether solvable.

    The “Processing” is the part where you want to do something else, not just
    wait for the data from the parent.

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

Sidebar

Related Questions

I'm trying to let the user input commands at a console using raw_input(), this
Since this function is implemented in IE8, I wanted to see exactly what I
Since enumeration uses integers, what other structure can I use to give me enum-like
I have two input fields. I want to force the focus on #area no
I have a label and input outputted from the shopping cart we are using.
I feel a little silly for asking this since I seem to be the
I'm trying to run an external program in SBCL and capture its output. The
I am trying to get input from the user at the command prompt. The
So this is my conclusion of the real problem from a question I asked
I want the program to pause and wait until you press any key to

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.