考虑以下python脚本
#test.py
import sys
inputfile=sys.argv[1]
with open(inputfile,'r') as f:
for line in f.readlines():
print line
with open(inputfile,'r') as f:
for line in f.readlines():
print line
现在我想test.py
在一个替代进程上运行,例如,
python test.py <( cat file | head -10)
似乎第二个f.readlines
返回空。为什么会这样,有没有办法在不必指定两个输入文件的情况下做到这一点?