I'm hoping y'all can help me get the correct semantics for code that sets up an external process, replaces Stdin, Stderr, Stdout, runs the command, calls exec.Command.Wait() and handles SIGKILL correctly.
I've read more than two dozen threads, PRs, and bug reports about how exec.Command interacts with io.Pipe and SIGKILL/cmd.Kill(). I've seen comments from Ian that some problems can't be solved and a few regrets about the current design but nothing that describes a working approach. What I want is a function that does this: ctx, cancelCmd := context.WithCancel(context.Background()) cmd := exec.CommandContext(ctx, cmdName, cmdArgs...) cmd.Stdin = stdinPipe cmd.Stdout = stdoutPipe cmd.Stderr = stderrPipe if err := cmd.Run(); err != nil { g.log.Warnf("Run error: %w", err) } return nil and that returns when the command exits, gets an (externally issued) SIGKILL, or gets a cancelCmd(). Every combination I've tried hangs because the pipes aren't closed. Although the pipes are monitored and drained (not shown), that doesn't help because the command doesn't get a chance to close them. What am I missing? Do I need a goroutine to watch the process table? Thank you! -- Salvatore smile. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAEQs7S9PhSrcE_6XuYW8Z2oYosuOw_EtUFPmkPf%2B%3DDee0ZCG-A%40mail.gmail.com.