-1

I've come across a program run by Python2, which asks many questions of yes/no type.

I want to answer "yes" to all of them, but it's really difficult because there are literally hundreds of them (it's basically a parser of code, which asks about every found variable).

So, is there any possibility, how to force Python answer "yes" automatically?

I think about something similar to apt-get -y install. And I'm interested in answers about both Python2 and Python3.

I'm using Lubuntu 16.10 and my default Shell is GNU bash, version 4.3.48.

cs95
  • 379,657
  • 97
  • 704
  • 746
Eenoku
  • 2,741
  • 4
  • 32
  • 64

1 Answers1

9

Try using yes:

yes | python ./script.py

If you have a more complex state to manage during interaction, there is also expect.

yes emits y by default, but you can customize it by providing an argument (e.g. yes yes), thanks @tobias_k. If you need a portable way (in Python), go with the suggestion from Jean-François Fabre (or just hack the script).

coredump
  • 37,664
  • 5
  • 43
  • 77