Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions subprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Subprocess struct {
process *exec.Cmd // The underlying *exec.Cmd that represents the subprocess.

args []string // The sanitized command arguments.
env []string // Environment variables for the subprocess.
hideStderr bool // Hide stderr output.
hideStdout bool // Hide stdout output.
shell bool // Executes the command directly in the shell without sanitization.
Expand Down Expand Up @@ -55,6 +56,16 @@ var (
s.context = path
}
}
EnvVars = func(envVars ...string) Option {
return func(s *Subprocess) {
s.env = append(s.env, envVars...)
}
}
EnvVar = func(envVar string) Option {
return func(s *Subprocess) {
s.env = append(s.env, envVar)
}
}
// Silent hides all output from the subprocess.
Silent Option = func(s *Subprocess) {
s.hideStdout = true
Expand Down Expand Up @@ -138,6 +149,10 @@ func (s *Subprocess) Exec() error {
return err
}

if s.env != nil {
cmd.Env = append(os.Environ(), s.env...)
}

stdout, err := cmd.StdoutPipe()
if err != nil {
return err
Expand Down