如何在golang中写入已经打开的FD
How to write to already opened FD in golang
我有以下打开的 FD(lsof 输出):
auth 11780 root 5w FIFO 0,10 0t0 72061824 pipe
我需要在 FD 5 (FIFO) 中写一些东西。在 C 中,它由系统调用 write():
执行
19270 write(5, "*************", 12 <unfinished ...>
提前致谢!
使用 os.NewFile
到 "open" 现有文件的文件描述符:
func NewFile(fd uintptr, name string) *File
NewFile returns a new File with the given file descriptor and name.
file := os.NewFile(5, "pipe")
_, err := file.Write([]byte(`my data`))
if err != nil {
panic(err)
}
我有以下打开的 FD(lsof 输出):
auth 11780 root 5w FIFO 0,10 0t0 72061824 pipe
我需要在 FD 5 (FIFO) 中写一些东西。在 C 中,它由系统调用 write():
执行19270 write(5, "*************", 12 <unfinished ...>
提前致谢!
使用 os.NewFile
到 "open" 现有文件的文件描述符:
func NewFile(fd uintptr, name string) *File
NewFile returns a new File with the given file descriptor and name.
file := os.NewFile(5, "pipe")
_, err := file.Write([]byte(`my data`))
if err != nil {
panic(err)
}