Python从命名管道获取数据
如何读取Python 3.5.3中的命名管道 管道的名称和位置为Python从命名管道获取数据,python,python-3.x,pipe,fifo,Python,Python 3.x,Pipe,Fifo,如何读取Python 3.5.3中的命名管道 管道的名称和位置为/tmp/shairport sync metadata,任何人都可以查看,但只能由shairport sync用户修改。 其他网站和问题说要使用os.mkfifo(“管道位置”),但我一直遇到这个错误: >>> import os >>> os.mkfifo("/tmp/shairport-sync-metadata") Traceback (most recent call last):
/tmp/shairport sync metadata
,任何人都可以查看,但只能由shairport sync
用户修改。
其他网站和问题说要使用os.mkfifo(“管道位置”)
,但我一直遇到这个错误:
>>> import os
>>> os.mkfifo("/tmp/shairport-sync-metadata")
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
os.mkfifo("/tmp/shairport-sync-metadata")
FileExistsError: [Errno 17] File exists
导入操作系统
>>>os.mkfifo(“/tmp/shairport同步元数据”)
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
os.mkfifo(“/tmp/shairport同步元数据”)
FileExistError:[Errno 17]文件存在
有没有办法绕过这个问题?很抱歉提出这个问题。用于创建先进先出。用于打开/读取已存在的fifo:
with open('/tmp/shairport-sync-metadata') as f: # add `rb` for binary mode
# line-by-line read
for line in f:
print(line)
# f.read(1024) # to read 1024 characters
谢谢我真蠢:P我注意到一件事,当我开始一首歌时,元数据被分成每首歌3行。这可能只是一个shairport同步,但这意味着在解析字符串时必须将它们连接在一起+1并接受。希望这有帮助。