Skip to content

Commit

Permalink
fix: exec param error
Browse files Browse the repository at this point in the history
  • Loading branch information
leafney committed Aug 13, 2023
1 parent 5685f70 commit c07d908
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 4 additions & 4 deletions exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func ExecCmdBashOutDir(dir string, arg ...string) (out string, err error) {
// ExecCmdBashOutDirCtx
// "/bin/bash", "-c", "command params"
func ExecCmdBashOutDirCtx(ctx context.Context, dir string, arg ...string) (out string, err error) {
arg = append(arg, SplitC)
arg = append([]string{SplitC}, arg...)
cmd := exec.CommandContext(ctx, Bash, arg...)
var stdOut bytes.Buffer
cmd.Stdout = &stdOut
Expand Down Expand Up @@ -324,7 +324,7 @@ func ExecCmdBashOutDirB(dir string, arg ...string) (out []byte, err error) {
// ExecCmdBashOutDirBCtx
// "/bin/bash", "-c", "command params"
func ExecCmdBashOutDirBCtx(ctx context.Context, dir string, arg ...string) (out []byte, err error) {
arg = append(arg, SplitC)
arg = append([]string{SplitC}, arg...)
cmd := exec.CommandContext(ctx, Bash, arg...)
var stdOut bytes.Buffer
cmd.Stdout = &stdOut
Expand Down Expand Up @@ -359,7 +359,7 @@ func ExecCmdBashOutErrDir(dir string, arg ...string) (out string, fail string, e
// ExecCmdBashOutErrDirCtx
// "/bin/bash", "-c", "command params"
func ExecCmdBashOutErrDirCtx(ctx context.Context, dir string, arg ...string) (out string, fail string, err error) {
arg = append(arg, SplitC)
arg = append([]string{SplitC}, arg...)
cmd := exec.CommandContext(ctx, Bash, arg...)
var stdOut, stdErr bytes.Buffer
cmd.Stdout = &stdOut // 标准输出
Expand Down Expand Up @@ -396,7 +396,7 @@ func ExecCmdBashOutErrDirB(dir string, arg ...string) (out []byte, fail []byte,
// ExecCmdBashOutErrDirBCtx
// "/bin/bash", "-c", "command params"
func ExecCmdBashOutErrDirBCtx(ctx context.Context, dir string, arg ...string) (out []byte, fail []byte, err error) {
arg = append(arg, SplitC)
arg = append([]string{SplitC}, arg...)
cmd := exec.CommandContext(ctx, Bash, arg...)
var stdOut, stdErr bytes.Buffer
cmd.Stdout = &stdOut // 标准输出
Expand Down
3 changes: 2 additions & 1 deletion exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import "testing"

func TestExecCmd(t *testing.T) {

o1, err := ExecCmdBashOut("pwd")
//o1, err := ExecCmdBashOut("pwd")
o1, err := ExecCmdBashOutDir("./reqx", "pwd")
if err != nil {
t.Log(err)
}
Expand Down

0 comments on commit c07d908

Please sign in to comment.