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.

4

2 回答 2

3

使用yes命令,下面的代码应该做你想做的事:

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

更多信息在这里

于 2013-03-04T05:50:28.630 回答
1

查看pexpect。您可以编写一个脚本来监视命令的输出,并做出适当的响应。

于 2013-03-04T05:43:53.143 回答