Code refactoring after #859

This commit is contained in:
Alex X
2024-04-30 06:42:17 +03:00
parent 7a0646fd5f
commit 52832223f8
7 changed files with 55 additions and 96 deletions
+26
View File
@@ -0,0 +1,26 @@
package stdin
import (
"errors"
"io"
"os/exec"
)
type pipeCloser struct {
io.Writer
io.Closer
cmd *exec.Cmd
}
func PipeCloser(cmd *exec.Cmd) (io.WriteCloser, error) {
stdin, err := cmd.StdinPipe()
if err != nil {
return nil, err
}
return pipeCloser{stdin, stdin, cmd}, nil
}
func (p pipeCloser) Close() (err error) {
return errors.Join(p.Closer.Close(), p.cmd.Process.Kill(), p.cmd.Wait())
}