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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:42:33+00:00 2026-06-04T21:42:33+00:00

I am using Python to execute an external program. And I would also like

  • 0

I am using Python to execute an external program. And I would also like Python to send some keystrokes to the called program to complete auto-login.

The problem is that when I used subprocess.call() to execute the external program, the program got the system focus and the Python script was not able to respond until I closed the external program.

Do you guys have any suggestion about this? Thanks a lot.

  • 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-04T21:42:34+00:00Added an answer on June 4, 2026 at 9:42 pm

    Use subprocess.Popen() instead of .call()

    With Popen you also can control stdin, stdout and stderr file descriptors, so you maybe can interact with the external program.

    Silly example:

    s = subprocess.Popen(command, stdout=subprocess.PIPE, 
                         stderr=subprocess.PIPE) # The script is not blocked here
    
    # Wait to finish
    while s.poll() is None: # poll() checks if process has finished without blocking
        time.sleep(1)
        ... # do something
    
    # Another way to wait
    s.wait() # This is blocking
    
    if s.returncode == 0:
        print "Everything OK!"
    else:
        print "Oh, it was an error"
    

    Some useful methods:

    Popen.poll() Check if child process has terminated. Set and return
    returncode attribute.

    Popen.wait() Wait for child process to terminate. Set and return
    returncode attribute.

    Popen.communicate(input=None) Interact with process: Send data to
    stdin. Read data from stdout and stderr, until end-of-file is reached.
    Wait for process to terminate. The optional input argument should be a
    string to be sent to the child process, or None, if no data should be
    sent to the child.

    Many more info in the docs

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

Sidebar

Related Questions

Can I simply execute Python program using PHP like this? (in a browser) exec(python
I'm using Java Scripting API to execute some external Python scripts from my Java
I would like to execute an external process in Ruby using spawn (for multiple
So far to execute a Python program, I'm using > python file.py I want
Using Python I would like to find the date object for last Wednesday. I
I have an external C# program which executes a Python script using the Process
I need to execute and send command to external app from python: .\Ext\PrintfPC /p
I'm using the Python unittest in order to test some other external application, but
I am using Python to execute the JVM for a specified Java class, like
I am running mongoimport command using python commands module as status = utilities.execute(mongoimport) in

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.