Skip to content

Instantly share code, notes, and snippets.

@achun
Created March 14, 2014 07:56
Show Gist options
  • Save achun/9543687 to your computer and use it in GitHub Desktop.
Save achun/9543687 to your computer and use it in GitHub Desktop.
build and run 合体技. 来自 Go编程语言群成员 四叶草 发的 gorun 代码.
package main
import (
"log"
"os"
"os/exec"
"path/filepath"
)
func main() {
wd, _ := os.Getwd()
fd := filepath.Base(wd)
// cmd := exec.Command("go", "build", fd)
cmd := exec.Command("go", "build")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
log.Fatalf("error build %v", err)
}
err = cmd.Wait()
cmd = exec.Command(fd)
for i := 1; i < len(os.Args); i++ {
cmd.Args = append(cmd.Args, os.Args[i])
}
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
cmd.Run()
cmd.Wait()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment