Skip to content

Commit

Permalink
add stdin to cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
xhd2015 committed Sep 16, 2024
1 parent e82e0eb commit 40aa40f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cmd/xgo/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import "fmt"

// auto updated
const VERSION = "1.0.48"
const REVISION = "ee7e3078596587e9734a1e6f208d258b8c6fa090+1"
const NUMBER = 305
const REVISION = "e82e0eba1db860999c91f1e94af190e17e1c9ce5+1"
const NUMBER = 306

// manually updated
const CORE_VERSION = "1.0.48"
Expand Down
9 changes: 9 additions & 0 deletions support/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type CmdBuilder struct {
dir string
debug bool
ignoreError bool
stdin io.Reader
stdout io.Writer
stderr io.Writer
}
Expand Down Expand Up @@ -58,6 +59,10 @@ func (c *CmdBuilder) Dir(dir string) *CmdBuilder {
c.dir = dir
return c
}
func (c *CmdBuilder) Stdin(stdin io.Reader) *CmdBuilder {
c.stdin = stdin
return c
}

func (c *CmdBuilder) Stdout(stdout io.Writer) *CmdBuilder {
c.stdout = stdout
Expand Down Expand Up @@ -126,6 +131,9 @@ func cmdExecEnv(cmd string, args []string, env []string, dir string, useStdout b

execCmd := exec.Command(cmd, args...)
execCmd.Stderr = stderr
if c != nil {
execCmd.Stdin = c.stdin
}
if len(env) > 0 {
execCmd.Env = os.Environ()
execCmd.Env = append(execCmd.Env, env...)
Expand All @@ -138,6 +146,7 @@ func cmdExecEnv(cmd string, args []string, env []string, dir string, useStdout b
execCmd.Stdout = os.Stdout
return "", execCmd.Run()
}

out, err := execCmd.Output()
outStr := strings.TrimSuffix(string(out), "\n")
if err != nil {
Expand Down

0 comments on commit 40aa40f

Please sign in to comment.