我的 python 脚本正在使用标准输入
用法是grep "asda" myfile" | python myscript.py
我用这种方式
lines = []
for line in fileinput.input():
lines.append(line)
它工作正常。
但现在我需要传递参数grep "asda" myfile" | python myscript.py -o out
我尝试使用 fileinput.input(sys.stdin) 仅从标准输入中获取行,但它失败了
Traceback (most recent call last):
File "parser.py", line 29, in <module>
for line in fileinput.input(sys.stdin):
File "/usr/lib/python2.7/fileinput.py", line 253, in next
line = self.readline()
File "/usr/lib/python2.7/fileinput.py", line 345, in readline
self._file = open(self._filename, self._mode)
IOError: [Errno 2] No such file or directory: '<Operation adaptorMethod="search" adaptorName="Search" status="Success" timeCreated="2013-10-15T02:43:33.728-0700" timeLastUpdated="2013-10-15T02:43:33.728-0700"/>\n'
grep 的输出包含这样的行
<Operation adaptorMethod="search" adaptorName="Search" status="Success" timeCreated="2013-10-15T02:43:33.728-0700" timeLastUpdated="2013-10-15T02:43:33.728-0700"/>
有人可以帮我吗?