I'm using go's ssh module, and I'm trying to pipe input from my program to the remote shell over stdin. This works as expected, printing Hello World
:
mySession := PrepareSession() // helper method to prepare a Connection and Session object
output, _ := mySession.Output("echo Hello World")
fmt.Println(output)
When I try to provide stdin input, however, it hangs on the line myStdin.Write("Hello World")
(I've confirmed this with a debugger):
mySession := PrepareSession()
myStdin, _ := mySession.StdinPipe()
myStdin.Write("Hello World")
output, _ := mySession.Output("cat /dev/stdin | echo")
fmt.Println(output)
Replacing myStdin.Write("Hello World")
with fmt.Fprint(myStdin, "Hello World")
yields the same problem.
Overall I just don't understand how pipes work in Go - how do I get the pipe to stop hanging when I feed input to it?