0

I am trying to issue an external shell command via python script. The external command prompts user to type 'Y' and hit enter to proceed further. How do I write the command in python script in a loop so that it does not prompts the user in every loop. I can grab a coffee and step out instead of sitting in front of the PC and hit Y every time I see the prompt.

My python script loops like

<for loop:>
 os.system(<External Command>)

I tried echoing "Y\n" but did not work.

asked Mar 4, 2013 at 5:38
1
  • Well...if all you're doing is accepting input from the user, is there any reason not to do that through raw_input or input if you're on Python 3.x? Commented Mar 4, 2013 at 5:43

2 Answers 2

3

use the yes command, the following code should do what you want:

<for loop:>
 os.system('yes Y | <external command>')

more info here

answered Mar 4, 2013 at 5:50
Sign up to request clarification or add additional context in comments.

Comments

1

Check out pexpect. You can write a script to watch for your command's output, and respond appropriately.

answered Mar 4, 2013 at 5:43

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.