From 86719ab303e7fa2a296046e3f2a85f84ecf6ebef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=9D=E5=A4=A7=E5=85=A8?= Date: Wed, 15 Aug 2018 00:05:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=94=AF=E6=8C=81=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0windows=E6=9C=8D=E5=8A=A1=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jobs/job.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/jobs/job.go b/jobs/job.go index f6db1a1..d161cdc 100644 --- a/jobs/job.go +++ b/jobs/job.go @@ -16,12 +16,14 @@ import ( "runtime/debug" "time" + "runtime" + "strconv" + "strings" + "github.com/astaxie/beego" "github.com/george518/PPGo_Job/models" "github.com/george518/PPGo_Job/notify" "golang.org/x/crypto/ssh" - "strconv" - "strings" ) type Job struct { @@ -72,7 +74,12 @@ func NewCommandJob(id int, name string, command string) *Job { bufOut := new(bytes.Buffer) bufErr := new(bytes.Buffer) //cmd := exec.Command("/bin/bash", "-c", command) - cmd := exec.Command("sh", "-c", command) + var cmd *exec.Cmd + if runtime.GOOS == "windows" { + cmd = exec.Command("sh", "-c", command) + } else { + cmd = exec.Command("CMD", "/C", command) + } cmd.Stdout = bufOut cmd.Stderr = bufErr cmd.Start()