I have this very simple code:
cmd := exec.Command("cat")
cmd.Stdout = os.Stdout
stdin, _ := cmd.StdinPipe()
file, _ := os.Open("file")
io.Copy(stdin, file)
_ = cmd.Run()
It works. But the problem is that cmd.Run()
never returns. It seems after writing the file to stdin, cat
still waits for more content.
I'm trying to do what cat <file
does, in which case cat
would exit after reading the file.
I wonder how to achieve that in go?