Reputation: 139
I have the following opened FD (lsof output):
auth 11780 root 5w FIFO 0,10 0t0 72061824 pipe
I need to write something in FD 5 (FIFO) in go. In C it is performed by the syscall write():
19270 write(5, "*************", 12 <unfinished ...>
Thank you in advance!
Upvotes: 7
Views: 4438
Reputation:
Use os.NewFile
to "open" an existing file by its file descriptor:
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)
}
Upvotes: 8