I have lots of python scripts to be run and I want to automate them. All of them accept inputs at certain times (3 in this case). I have tried something like this but since echo does not have an EOF it did not work:
os.system("echo 4 | echo 5 | echo 6 | python script.py")
I cannot change the content of script.py and it does not accept arguments to it.
How can I automatically input using a line(s) of python code? Thanks.
6into the Python script. Piping input toechomakes no sense as it ignores its standard input. Probably you meanprintf '%s\n' 4 5 6 | python script.py. A much better solution is usually toimport scriptand run it within your existing script, instead of as a subprocess (though there are scenarios where you do want two processes, such as when you need to be able to interrupt or kill the subprocess from the parent).