Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 package main | |
| 2 | |
| 3 import "fmt" | |
| 4 import "os" | |
| 5 import "os/exec" | |
| 6 import "strings" | |
| 7 | |
| 8 func failIf(err error) { | |
| 9 if err != nil { | |
| 10 fmt.Println("fatal:", err) | |
| 11 os.Exit(1) | |
|
M-A Ruel
2014/10/18 00:47:06
That's a bit severe and hard to test.
| |
| 12 } | |
| 13 } | |
| 14 | |
| 15 func SplitLines(data string) []string { | |
| 16 return strings.Split(strings.TrimRight(data, "\n"), "\n") | |
| 17 } | |
| 18 | |
| 19 func Shell(dir string) bool { | |
| 20 shell := os.Getenv("SHELL") | |
| 21 if shell == "" { | |
| 22 shell = DefaultShell | |
| 23 } | |
| 24 shell, err := exec.LookPath(shell) | |
| 25 failIf(err) | |
| 26 p, err := os.StartProcess(shell, []string{shell}, &os.ProcAttr{ | |
| 27 Dir: dir, | |
| 28 Files: []*os.File{os.Stdin, os.Stdout, os.Stderr}, | |
| 29 }) | |
| 30 failIf(err) | |
| 31 s, err := p.Wait() | |
| 32 failIf(err) | |
| 33 | |
| 34 return s.Success() | |
| 35 } | |
| OLD | NEW |