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
import (
"fmt"
"go/build"
"os"
"os/exec"
"github.com/codegangsta/cli"
"github.com/gpmgo/gopm/log"
)
@ -36,32 +30,15 @@ gopm run <go run commands>`,
}
func runRun(ctx *cli.Context) {
gopath := build.Default.GOPATH
genNewGoPath(ctx)
log.Trace("Running...")
cmdArgs := []string{"go", "run"}
cmdArgs = append(cmdArgs, ctx.Args()...)
bCmd := exec.Command(cmdArgs[0], cmdArgs[1:]...)
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)
err := execCmd(newGoPath, newCurPath, cmdArgs...)
if err != nil {
log.Error("Run", "Fail to set back GOPATH")
log.Error("Run", "Fail to run program")
log.Fatal("", err.Error())
}

Loading…
Cancel
Save