Skip to content

Commit

Permalink
Improve run support for arbitrary commands
Browse files Browse the repository at this point in the history
Commands like `doppler run "node && node"` or `doppler run -- node -v` were failing to execute. This change passes the user's command to a new shell to improve compatability.
  • Loading branch information
Piccirello committed Dec 31, 2019
1 parent 53c6595 commit 23dd7b9
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pkg/utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"path/filepath"
"runtime"
"strconv"
"strings"
"time"

"github.com/AlecAivazis/survey/v2"
Expand Down Expand Up @@ -67,7 +68,12 @@ func Cwd() string {

// RunCommand runs the specified command
func RunCommand(command []string, env []string) (int, error) {
cmd := exec.Command(command[0], command[1:]...)
shell := [2]string{"sh", "-c"}
if IsWindows() {
shell = [2]string{"cmd", "/C"}
}

cmd := exec.Command(shell[0], shell[1], strings.Join(command, " "))
cmd.Env = env
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
Expand Down Expand Up @@ -215,3 +221,7 @@ func HostArch() string {

return arch
}

func IsWindows() bool {
return runtime.GOOS == "windows"
}

0 comments on commit 23dd7b9

Please sign in to comment.