How do I start a Python script with some input already waiting in stdin. For example, say I have this simple script located in main.py
, using Python3:
mystr = input()
print(mystr)
If you just called python3 main.py
from the terminal, the script would pause and wait for you to type something. After hitting enter it would continue and print out what you typed. But is there a way to place something into stdin before the script executes? That way the script wouldn't pause, it would accept what's already there. I was envisioning something like:
python3 main.py | my string
but that doesn't work.
Note that I am not asking about command line arguments: I am writing an application which will have to take input from stdin, so I am looking for a convenient solution to test out that environment.