Browse Source

change run command use execCommand method

pull/103/head
Lunny Xiao 11 years ago
parent
commit
49fe9b7d03
  1. 31
      cmd/run.go

31
cmd/run.go

@ -15,13 +15,7 @@
package cmd package cmd
import ( import (
"fmt"
"go/build"
"os"
"os/exec"
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
"github.com/gpmgo/gopm/log" "github.com/gpmgo/gopm/log"
) )
@ -36,32 +30,15 @@ gopm run <go run commands>`,
} }
func runRun(ctx *cli.Context) { func runRun(ctx *cli.Context) {
gopath := build.Default.GOPATH
genNewGoPath(ctx) genNewGoPath(ctx)
log.Trace("Running...")
cmdArgs := []string{"go", "run"} cmdArgs := []string{"go", "run"}
cmdArgs = append(cmdArgs, ctx.Args()...) cmdArgs = append(cmdArgs, ctx.Args()...)
bCmd := exec.Command(cmdArgs[0], cmdArgs[1:]...) err := execCmd(newGoPath, newCurPath, cmdArgs...)
bCmd.Stdout = os.Stdout
bCmd.Stderr = os.Stderr
log.Log("===== application outputs start =====\n")
err := bCmd.Run()
fmt.Println()
log.Log("====== application outputs end ======")
if err != nil {
log.Error("Run", "Fail to execute")
log.Fatal("", err.Error())
}
log.Trace("Set back GOPATH=%s", gopath)
err = os.Setenv("GOPATH", gopath)
if err != nil { if err != nil {
log.Error("Run", "Fail to set back GOPATH") log.Error("Run", "Fail to run program")
log.Fatal("", err.Error()) log.Fatal("", err.Error())
} }

Loading…
Cancel
Save