Skip to content

Commit d6d3c21

Browse files
committed
2019年 04月 12日 星期五 14:55:16 CST
1 parent 94449f8 commit d6d3c21

2 files changed

Lines changed: 7 additions & 29 deletions

File tree

wrapcommand_linux.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package main
22

33
import (
44
"os/exec"
5-
"reflect"
65
)
76

87
type myCommand struct {
@@ -16,17 +15,7 @@ func newMyCommand(name string, args []string, envs []string) *myCommand {
1615
}
1716

1817
func (s *myCommand) GetCmd() *exec.Cmd {
19-
f := reflect.ValueOf(exec.Command)
20-
argv := []reflect.Value{}
21-
for _, v := range s.Args {
22-
argv = append(argv, reflect.ValueOf(v))
23-
}
24-
ret := f.Call(argv)
25-
if len(ret) == 0 {
26-
return nil
27-
} else {
28-
cmd := ret[0].Interface().(*exec.Cmd)
29-
cmd.Env = s.Envs
30-
return cmd
31-
}
18+
cmd := exec.Command(s.Name, s.Args[1:]...)
19+
cmd.Env = s.Envs
20+
return cmd
3221
}

wrapcommand_windows.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package main
22

33
import (
44
"os/exec"
5-
"reflect"
65
"syscall"
76
)
87

@@ -17,18 +16,8 @@ func newMyCommand(name string, args []string, envs []string) *myCommand {
1716
}
1817

1918
func (s *myCommand) GetCmd() *exec.Cmd {
20-
f := reflect.ValueOf(exec.Command)
21-
argv := []reflect.Value{}
22-
for _, v := range s.Args {
23-
argv = append(argv, reflect.ValueOf(v))
24-
}
25-
ret := f.Call(argv)
26-
if len(ret) == 0 {
27-
return nil
28-
} else {
29-
cmd := ret[0].Interface().(*exec.Cmd)
30-
cmd.Env = s.Envs
31-
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
32-
return cmd
33-
}
19+
cmd := exec.Command(s.Name, s.Args[1:]...)
20+
cmd.Env = s.Envs
21+
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
22+
return cmd
3423
}

0 commit comments

Comments
 (0)