One can redirect input from a file with the < operator. So if I have a Python script, like:
name = input("Enter your name: ") print("Hello", name)
Then I can put the input in a file like this:
And then run it with this:
$ python program.py < input.txt
When doing this, the output looks like this:
What is your name? Hello Bob
Is there any way to have the input text appear on the screen as well, so that it looks the same as if you ran the program normally? For the example above, it would look like this:
What is your name? Bob Hello Bob
The reason that I want this is because I am working on a book which has code examples, and I want to automate running the programs and having the output appear in the book. I don't know if this is possible, but it would make the whole process much easier since I can just write the programs, and setup the input files, and then have the rest happen automatically!
Thanks for reading!