github.com/weaveworks/common@v0.0.0-20230728070032-dd9e68f319d5/exec/exec.go (about)

     1  package exec
     2  
     3  import (
     4  	"io"
     5  	"os/exec"
     6  )
     7  
     8  // Cmd is a hook for mocking
     9  type Cmd interface {
    10  	StdoutPipe() (io.ReadCloser, error)
    11  	StderrPipe() (io.ReadCloser, error)
    12  	Start() error
    13  	Wait() error
    14  	Kill() error
    15  	Output() ([]byte, error)
    16  	Run() error
    17  	SetEnv([]string)
    18  }
    19  
    20  // Command is a hook for mocking
    21  var Command = func(name string, args ...string) Cmd {
    22  	return &realCmd{exec.Command(name, args...)}
    23  }
    24  
    25  type realCmd struct {
    26  	*exec.Cmd
    27  }
    28  
    29  func (c *realCmd) Kill() error {
    30  	return c.Cmd.Process.Kill()
    31  }
    32  
    33  func (c *realCmd) SetEnv(env []string) {
    34  	c.Cmd.Env = env
    35  }