Hello! this is my first question on StackOverflow please guide me if I do something incorrectly.
so I have a python script and I want to make a shell script to pipe text file to the python when run.
the problem is the text from file piping to python is not display on the screen.
here is the code that I tried:
python3 index.py < input.txt
index.py
while True:
x = input("Input: ")
print("Input ->", x)
input.txt:
Test1
Test2
Test3
and after I try to run the command the result is:
Input: Input -> Test1
Input: Input -> Test2
Input: Input -> Test3
Input: Input ->
Input: Traceback (most recent call last):
File "index.py", line 2, in <module>
x = input("Input: ")
EOFError: EOF when reading a line
(ignore the error)
the text from piping not display. more than that it does not even display the new line.
sadly, that is not the result that I want :(
here is the result that I expected:
Input: Test1
Input -> Test1
Input: Test2
Input -> Test2
Input: Test3
Input -> Test3
...
I already try the following commands:
cat input.txt | python3 index.py
the result just like above.
here is another way that I tried:
cat input.txt | tee /dev/tty | python3 index.py
the result is still not what I expected:
Test1
Test2
Test3
Input: Input -> Test1
Input: Input -> Test2
Input: Input -> Test3
I also take a look at the screen command by start a detached screen session and send the text via -X stuff "Test1^M"
but the problem is I don't want to make a shell script something like looping text line and using screen command to send it. (I want python to read stdin as fast as possible)
is this possible with pure shell script?
thank you for your further answer.