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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:51:26+00:00 2026-06-13T22:51:26+00:00

I have a python program which uses various Bash shell scripts. However, some of

  • 0

I have a python program which uses various Bash shell scripts. However, some of them require (y/n) input. I know the input required based on the question number so it’s a matter of being able to provide that automatically.

Is there a way in Python to do that?

As a last resort I can send a signal to a window etc. but I’d rather not do that.

  • 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-13T22:51:27+00:00Added an answer on June 13, 2026 at 10:51 pm

    Probably the the easiest way is to use pexpect. An example (from the overview in the wiki):

    import pexpect
    
    child = pexpect.spawn('ftp ftp.openbsd.org')
    child.expect('Name .*: ')
    child.sendline('anonymous')
    child.expect('Password:')
    child.sendline('noah@example.com')
    child.expect('ftp> ')
    child.sendline('cd pub')
    child.expect('ftp> ')
    child.sendline('get ls-lR.gz')
    child.expect('ftp> ')
    child.sendline('bye')
    

    If you don’t want to use an extra module, using subprocess.Popen is the way to go, but it is more complicated. First you create the process.

    import subprocess
    
    script = subprocess.Popen(['script.sh'], stdin=subprocess.PIPE,
                              stdout=subprocess.PIPE, shell=True)
    

    You can either use shell=True here, or prepend the name of the shell to the command arguments. The former is easier.

    Next you need to read from script.stdout until you find your question number. Then you write the answer to script.stdin.

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

Sidebar

Related Questions

I have a Python program that uses psutil to run some various twistd ...
I have a small Python program, which uses a Google Maps API secret key.
I have been trying to create a simple program with Python which uses OpenCV
I have a python program which calls a C function. I send some structures
I have a python program which takes input from stdin. Now, I've to write
I have a shell script which runs a python program which has its own
I have a python program which needs to clean up something when the shell
I have a simple Python program which uses a read-eval-print loop to read user
I have a source of python program which doesn't have any documentation or comments.
I have a small Python OOP program in which 2 class, Flan and Outil

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.