@@ -25,7 +25,6 @@ import (
25
25
"github.com/chaosblade-io/chaosblade-spec-go/util"
26
26
os_exec "os/exec"
27
27
"path"
28
- "strings"
29
28
"syscall"
30
29
)
31
30
@@ -47,26 +46,27 @@ func (e *Executor) Exec(uid string, ctx context.Context, model *spec.ExpModel) *
47
46
return sshExecutor .Exec (uid , ctx , model )
48
47
}
49
48
50
- var args string
51
- var flags string
49
+ var mode string
50
+ var argsArray []string
51
+
52
+ _ , isDestroy := spec .IsDestroy (ctx )
53
+ if isDestroy {
54
+ mode = spec .Destroy
55
+ } else {
56
+ mode = spec .Create
57
+ }
58
+
59
+ argsArray = append (argsArray , mode , model .Target , model .ActionName , fmt .Sprintf ("--uid=%s" , uid ))
52
60
for k , v := range model .ActionFlags {
53
61
if v == "" || k == "timeout" {
54
62
continue
55
63
}
56
- flags = fmt .Sprintf ("%s --%s=%s" , flags , k , v )
64
+ argsArray = append ( argsArray , fmt .Sprintf ("--%s=%s" , k , v ) )
57
65
}
58
66
59
- _ , isDestroy := spec .IsDestroy (ctx )
60
-
61
- if isDestroy {
62
- args = fmt .Sprintf ("%s %s %s%s uid=%s" , spec .Destroy , model .Target , model .ActionName , flags , uid )
63
- } else {
64
- args = fmt .Sprintf ("%s %s %s%s uid=%s" , spec .Create , model .Target , model .ActionName , flags , uid )
65
- }
66
67
chaosOsBin := path .Join (util .GetProgramPath (), "bin" , spec .ChaosOsBin )
67
- argsArray := strings .Split (args , " " )
68
68
command := os_exec .CommandContext (ctx , chaosOsBin , argsArray ... )
69
- log .Debugf (ctx , "run command, %s %s " , chaosOsBin , args )
69
+ log .Debugf (ctx , "run command, %s %v " , chaosOsBin , argsArray )
70
70
71
71
if model .ActionProcessHang && ! isDestroy {
72
72
if err := command .Start (); err != nil {
0 commit comments