-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
StartWithStdin channel keeps blocking after process stops #56
Comments
Hi. Sorry, I don't understand the direction of programs. You said,
But in the sample code above, the C program is sending to the Go code? |
Hi, thanks for responding. Yes, the C program above is a minimal example to demonstrate the issue. |
Does Go code also read on stdin? If so, then it's like By the way, when I ran the example code above, nothing blocked, but I'm not sure if it's a functional example because |
The example does not read on stdin. I have created a small repository with a working example you can easily run: |
@joepadmiraal, this is expected behaviour.
Try this in your demo code, and it will no longer hang:
|
Ok, but doesn't that make it impossible to detect whether a program has stopped? If I want to stop the program from the Go code I can send the EOF via the reader. |
I agree, I have to use a hacky workaround to detect if the program is still running (using gopsutil). |
This is an edge case with io.Pipe usage within exec.Cmd iteslf, not go-cmd:
I'd expect a zero-length payload to detect whether a pipe was broken as well (e.g TCP) |
I had a look at what exec.Cmd has to offer and it seems they have something called Would it make sense to change the go-cmd implementation to start using |
I also encountered the same problem , are you have resolved the issue? |
How about using reader, writer := io.Pipe()
go func() {
_, _ = io.Copy(writer, bytes.NewBufferString("hello from the other side\n"))
// close immediately
_ = writer.Close()
}()
statusChan := testCmd.StartWithStdin(reader)
... Will not block, the buffer is sent to the child process stdin |
Thanks for maintaining go-cmd.
I've got a C program that get's started with
stdin
.This allows the Go code to send instructions over
stdin
to the C program.However if the C program finishes, the
cmd.Status
chan does not seem to unblock.Is there something I'm doing wrong here?
Go code:
C code:
The text was updated successfully, but these errors were encountered: