Neil
Neil

Reputation: 6039

Enter/Return command in Shell script

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.

Upvotes: 0

Views: 374

Answers (2)

swpd
swpd

Reputation: 1151

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

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

more info here

Upvotes: 3

Neil
Neil

Reputation: 2438

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

Upvotes: 1

Related Questions