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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:06:35+00:00 2026-06-16T17:06:35+00:00

I have a little test.sh script that I run from the command line ./test.sh

  • 0

I have a little test.sh script that I run from the command line ./test.sh and it will ask me for input to 2 questions that I enter, then it loops till I ctrl-c out of it.

I want to write a little python script that can run my test.sh, and enter the inputs to the script questions from variables, var1 and var2 that I set in python.

I also want to have another variable, var3, that loops for x long and runs my test.sh, and ends it then relaunches it every x minutes based on the value of var3

I wrote this code but it doesn’t seem to pass the commands into my test.sh after it launches:

import os
os.system('./test.sh arg1')
time.sleep(10)
sh('input answer 1')
time.sleep(5)
sh('input answer 2')

Currently my code has been updated based on this thread to look like this:

#!/usr/bin/env python

import pexpect
import sys
import os
child = pexpect.spawn ('./test.sh -arg1')
child.expect ('some expected output from the .sh file')
child.expect ('more expected output from the .sh file')
child.expect ('(?i)Enter Username:')
child.sendline ('myusername')
child.expect ('(?i)Enter Password:')
child.sendline ('mypassword')
# sys.stdout.write (child.after)
# sys.stdout.flush()
time.sleep(30)
child.sendcontrol('c')
child.close()
print 'Goodbye'

–fixed– Now the problem is my timeout or sleep is getting inturrupted, possibly by my .sh script’s output. When I run this script with either timeout or time.sleep uncommented, it either has no affect and goes straight down the line to my child.close() and ends the program, or it hangs up the child.sendline (‘mypassword’) for some reason and I get stuck at my .sh script’s password prompt… maybe it’s not really stuck there because I can’t interact with it. –fixed–

Once I get the script pausing for 30 seconds (or x) then all I will have left to do is make the whole thing loop x times. Finnaly I’ll need to add error checking because the .SH responds with different strings of text that can indicate I need to run the script again right away.

Thanks for everyone’s help so much!

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

    Using pexpect:

    import pexpect  # $ pip install pexpect
    
    while var3:  # start ./test.sh again
        output = pexpect.run('./test.sh arg1', 
            timeout=x,  # terminate child process after x seconds
            events={r'(?i)question 1': var1,  # provide answers
                    r'(?i)question 2': var2})  
    

    Note: subprocess-based solution might be more complex due to buffering issues and it might require additionally pty, select modules, example.

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

Sidebar

Related Questions

I have a little JUnit-Test that export an Object to the FileSystem. In the
I have a little foundation tool test (Objective-C) that I am playing with and
On a client server, we have a little script that send an email at
I have a little php script that goes to mySql database. I want to
I have written a little script in Python that I use to append text
I have a working script that passes a value from a popup page to
Greetings. I have written a little python script that calls MySQL in a subprocess.
So I have a little Linux problem, geez that will teach me to spend
I'm working on a little script that generates a sprite sheet. I have 6
I have created a little test project to try to resolve a problem I

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.