From befb16c2b849b4b49d1084782db6f8f91d1befee Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 28 Aug 2014 10:19:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9E=84=E5=BB=BA=E6=97=B6=E5=88=87=E6=8D=A2?= =?UTF-8?q?=20GOPATH?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- output/outputs.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/output/outputs.go b/output/outputs.go index 6774409..6be1e2a 100644 --- a/output/outputs.go +++ b/output/outputs.go @@ -2,6 +2,7 @@ package output import ( "encoding/json" + "github.com/b3log/wide/conf" "github.com/b3log/wide/session" "github.com/golang/glog" "github.com/gorilla/websocket" @@ -151,6 +152,9 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) { cmd := exec.Command("go", argv...) cmd.Dir = curDir + // 设置环境变量(设置当前用户的 GOPATH 等) + setCmdEnv(cmd) + glog.Infof("go build -o %s %s", executable, filePath) executable = curDir + string(os.PathSeparator) + executable @@ -208,3 +212,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") w.Write(ret) } + +func setCmdEnv(cmd *exec.Cmd) { + cmd.Env = append(cmd.Env, "GOPATH="+conf.Wide.GOPATH, "GOROOT="+os.Getenv("GOROOT")) +}