🚸 [agent v0.3.3] 优化多行及带参命令执行

This commit is contained in:
naiba
2021-01-28 23:19:59 +08:00
parent c55cb942b3
commit e914dd8135
5 changed files with 30 additions and 4 deletions

View File

@@ -11,6 +11,7 @@ import (
"time"
"github.com/go-ping/ping"
"github.com/naiba/nezha/pkg/utils"
"github.com/shirou/gopsutil/v3/disk"
)
@@ -77,7 +78,13 @@ func cmdExec() {
if err != nil {
panic(err)
}
cmd := exec.Command(execFrom + "/cmd/playground/example.sh")
var cmd *exec.Cmd
if utils.IsWindows() {
cmd = exec.Command("cmd", "/c", execFrom+"/cmd/playground/example.sh hello asd")
} else {
cmd = exec.Command("sh", "-c", execFrom+`/cmd/playground/example.sh hello && \
echo world!`)
}
output, err := cmd.Output()
log.Println("output:", string(output))
log.Println("err:", err)