I want to pipe the output of a command to another command, but I want to be able to type things into stdin like I can without a pipe when the pipe is broken by the first command.
cat file.txt | python -i script.py
cat file.txt | python -i script.py
will exit the python interpreter immediately when the file is fully processed.
As you are using a.txt file, I suggest another way to process to your demand:
import sys
inFile = sys.argv[1]
with open(inFile,'r') as i:
lines = i.readlines()
You can call this program by running:
$ python script.py file.txt
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.