I have a python program which uses various Bash shell scripts. However, some of them require (y/n) input. I know the input required based on the question number so it’s a matter of being able to provide that automatically.
Is there a way in Python to do that?
As a last resort I can send a signal to a window etc. but I’d rather not do that.
Probably the the easiest way is to use pexpect. An example (from the overview in the wiki):
If you don’t want to use an extra module, using
subprocess.Popenis the way to go, but it is more complicated. First you create the process.You can either use
shell=Truehere, or prepend the name of the shell to the command arguments. The former is easier.Next you need to read from
script.stdoutuntil you find your question number. Then you write the answer toscript.stdin.