python os.mkfifo() for Windows(用于 Windows 的 python os.mkfifo())
问题描述
短版(如果你能回答短版它对我有用,其余的主要是为了其他有类似任务的人的利益):
Short version (if you can answer the short version it does the job for me, the rest is mainly for the benefit of other people with a similar task):
在 Windows 的 python 中,我想创建 2 个文件对象,附加到同一个文件(它不必是硬盘驱动器上的实际文件),一个用于读取,一个用于写入,这样如果读取端尝试读取它永远不会得到 EOF(它只会阻塞直到写入某些内容).我认为在 linux os.mkfifo() 中可以完成这项工作,但在 Windows 中它不存在.可以做什么?(我必须使用文件对象).
In python in Windows, I want to create 2 file objects, attached to the same file (it doesn't have to be an actual file on the hard-drive), one for reading and one for writing, such that if the reading end tries to read it will never get EOF (it will just block until something is written). I think in linux os.mkfifo() would do the job, but in Windows it doesn't exist. What can be done? (I must use file-objects).
一些额外的细节:我有一个 python 模块(不是我写的),它通过标准输入和标准输出(使用 raw_input() 和打印)玩某个游戏.我也有一个 Windows 可执行文件通过标准输入和标准输出玩同样的游戏.我想让他们互相对战,并记录他们的所有交流.
Some extra details: I have a python module (not written by me) that plays a certain game through stdin and stdout (using raw_input() and print). I also have a Windows executable playing the same game, through stdin and stdout as well. I want to make them play one against the other, and log all their communication.
这是我可以编写的代码(get_fifo()
函数没有实现,因为我不知道在 Windows 中这样做):
Here's the code I can write (the get_fifo()
function is not implemented, because that's what I don't know to do it Windows):
推荐答案
按照上面两个答案,不小心碰到了答案.os.pipe() 完成了这项工作.谢谢你的回答.
Following the two answers above, I accidentally bumped into the answer. os.pipe() does the job. Thank you for your answers.
我发布完整的代码以防其他人正在寻找这个:
I'm posting the complete code in case someone else is looking for this:
这篇关于用于 Windows 的 python os.mkfifo()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!