Created
March 14, 2014 07:56
-
-
Save achun/9543687 to your computer and use it in GitHub Desktop.
build and run 合体技. 来自 Go编程语言群成员 四叶草 发的 gorun 代码.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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