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
cmd/go: run does not close its own os.Stdout when the underlying process does so #39172
Comments
One problem: |
Note that |
go run
does not close its own os.Stdout when the underlying process does so
Yeah, if |
Acknowledging I could dig further into this to find what exactly needs fixing, I just ran out of time figuring the initial cause. What I would like to hear first is whether this is something that the core team considers an actual error in behavior. P.S. In my specific case I will have to devise some sort of workaround in any case, because telling users "check out this repo and play with it, but oh wait, you can't use |
It's not a bug in the implementation of fork/exec, which in this case is the os/exec package (https://golang.org/pkg/os/exec). That lets you set standard output to whatever you want. As you say, that doesn't work for programs that expect to be able to close their own standard output and have that close be seen by processes later in the pipeline. |
It seems to me that you're over-blowing this... You wanted to write:
Instead, you have to write:
I even like the 2nd version better! I find the |
@ianlancetaylor looking through the code more I see what is happening... It is a really unfortunate design decision that @ALTree the "you are holding it wrong" tone is really unnecessary. The project in question requires/invites the user to tweak the source. The extra |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
✔️ ( fails the same way on multiple go versions )
What operating system and processor architecture are you using (
go env
)?macos Mojave
What did you do?
I have applications needing to communicate over multiple FIFO's in turn (due to boring/non-negotiable external requirements). The dance looks like:
Where:
ProducerProgram
creates a number of named pipes, prints their names, closes STDOUT, and starts writing to each FIFO in turnxargs
sees theEOF
, starts theConsumerProgram
with the FIFOs as args and it proceeds reading from each FIFO in the same orderThe trouble is that
go build; ./ProducerProgram ... |
works, whilego run ./. ... |
does not, asgo run
does not propagate the closure ofos.Stdout
until program exit... which can never happen because the FIFO reading never starts.Below find a complete program that exhibits the problem as:
Standalone program to reproduce
The text was updated successfully, but these errors were encountered: