Named Pipes in Go for both Windows and Linux

huangapple go评论78阅读模式
英文:

Named Pipes in Go for both Windows and Linux

问题

我是你的中文翻译助手,以下是你要翻译的内容:

我刚开始学习Go语言,我想在Go中创建一个在Windows和Linux上都能工作的命名管道实现。

我已经成功在Ubuntu上运行了代码,但是在Windows上却不起作用。

在Go中没有任何抽象层可以让你在这两个环境下使用命名管道吗?

以下是我代码的一部分:

// 创建管道:在Windows上不起作用
syscall.Mkfifo("tmpPipe", 0666)

// 打开管道进行写入
file, err1 := os.OpenFile("tmpPipe", os.O_RDWR, os.ModeNamedPipe)

// 打开管道进行读取
file, err := os.OpenFile("tmpPipe", os.O_RDONLY, os.ModeNamedPipe)

任何帮助或指导都将非常有帮助。谢谢!

英文:

I am new to Go, I want to create Named Pipes implementation in Go which works on both Windows and Linux.

I managed to get the code working on Ubuntu, but this one does not work on Windows

Isn't there any abstraction in Go which allows you to work with Named Pipes in both environment

Below is piece of my code

//to create pipe: does not work in windows    
syscall.Mkfifo("tmpPipe", 0666)    

// to open pipe to write    
file, err1 := os.OpenFile("tmpPipe", os.O_RDWR, os.ModeNamedPipe)    

//to open pipe to read    
file, err := os.OpenFile("tmpPipe", os.O_RDONLY, os.ModeNamedPipe)

Any help or pointers would help a lot. Thanks

答案1

得分: 10

根据https://github.com/golang/go/issues/3599:

nate的软件包看起来很好,任何人都可以使用"go get"获取它。

一个纯Go编写的Windows命名管道实现:
https://github.com/natefinch/npipe

这个项目启发了(用于Go的Win32 IO相关工具):
https://github.com/Microsoft/go-winio

英文:

According to https://github.com/golang/go/issues/3599

> nate's package looks nice, and anyone can "go get" it.

A Windows named pipe implementation written in pure Go:
https://github.com/natefinch/npipe

Which has inspired (Win32 IO-related utilities for Go):
https://github.com/Microsoft/go-winio

答案2

得分: 4

这是一个来自Microsoft的用于Windows的Go语言命名管道的实现:

https://github.com/Microsoft/go-winio

英文:

There is an implementation of named pipes for Windows in Go from Microsoft:

https://github.com/Microsoft/go-winio

huangapple
  • 本文由 发表于 2016年9月9日 16:53:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/39407592.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定