本文整理汇总了Golang中exec.LookPath函数的典型用法代码### 示例。如果您正苦于以下问题:Golang LookPath函数的具体用法?Golang LookPath怎么用?Golang LookPath使用的例子?那么恭喜您, 这里精选的函数代码### 示例或许可以为您提供帮助。
在下文中一共展示了LookPath函数的20个代码### 示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码### 示例。
示例1: Compile
// Compile compiles and links sourcefile and atomically renames the
// resulting binary to runfile.
func Compile(sourcefile, runfile string, useGd bool) (err os.Error) {
pid := strconv.Itoa(os.Getpid())
content, err := ioutil.ReadFile(sourcefile)
if len(content) > 2 && content[0] == '#' && content[1] == '!' {
content[0] = '/'
content[1] = '/'
sourcefile = runfile + "." + pid + ".go"
ioutil.WriteFile(sourcefile, content, 0600)
defer os.Remove(sourcefile)
}
bindir := filepath.Join(runtime.GOROOT(), "bin")
if useGd {
gd := filepath.Join(bindir, "mgd")
if _, err := os.Stat(gd); err != nil {
if gd, err = exec.LookPath("mgd"); err != nil {
return os.NewError("can't find mgd")
}
}
err = Exec([]string{gd, "-L", "_obj", ".", "-q", "-o", runfile})
return err
} else {
n := TheChar()
gc := filepath.Join(bindir, n+"g")
ld := filepath.Join(bindir, n+"l")
if _, err := os.Stat(gc); err != nil {
if gc, err = exec.LookPath(n + "g"); err != nil {
return os.NewError("can't find " + n + "g")
}
}
if _, err := os.Stat(ld); err != nil {
if ld, err = exec.LookPath(n + "l"); err != nil {
return os.NewError("can't find " + n + "l")
}
}
gcout := runfile + "." + pid + "." + n
ldout := runfile + "." + pid
err = Exec([]string{gc, "-o", gcout, sourcefile})
if err != nil {
return err
}
defer os.Remove(gcout)
err = Exec([]string{ld, "-o", ldout, gcout})
if err != nil {
return err
}
return os.Rename(ldout, runfile)
}
panic("Unreachable code")
}
开发者ID:ssrl,项目名称:gonrun,代码行数:54,代码来源:gonrun.go
示例2: main
func main() {
flag.Parse()
cwd, _ := os.Getwd()
binary, _ := exec.LookPath(flag.Args()[0])
for {
cmd, _ := exec.Run(binary, flag.Args(), nil, cwd, exec.PassThrough, exec.PassThrough, exec.PassThrough)
pid := cmd.Process.Pid
extras := make(ABC, 0)
if *httpTimeoutUrl != "" {
extras = append(extras, setupHttpTimeoutCheck(pid))
}
if *httpStatusUrl != "" {
extras = append(extras, setupHttpStatusCheck(pid))
}
if *maxMemory > 0 {
extras = append(extras, setupMaxMemoryCheck(pid))
}
cmd.Wait(os.WSTOPPED)
println("Process died, restarting.")
extras.closeAll()
}
}
开发者ID:darkhelmet,项目名称:sniper,代码行数:26,代码来源:scout-sniper.go
示例3: envOrDefault
func envOrDefault(cmd, dfl string) string {
p, err := exec.LookPath(cmd)
if err != nil {
return dfl
}
return p
}
开发者ID:andradeandrey,项目名称:Faff,代码行数:7,代码来源:main.go
示例4: ExecRead
func ExecRead(cmd string, args ...string) (out []byte, err os.Error) {
abscmd, err := exec.LookPath(cmd)
if err != nil {
return out, os.NewError("Couldn't find " + cmd + ": " + err.String())
}
cmdargs := make([]string, len(args)+1)
cmdargs[0] = cmd
for i, a := range args {
cmdargs[i+1] = a
}
printexec(cmd, args)
pid, err := exec.Run(abscmd, cmdargs, nil, "",
exec.PassThrough, exec.Pipe, exec.PassThrough)
if err != nil {
return
}
out, err = ioutil.ReadAll(pid.Stdout)
if err != nil {
return
}
ws, err := pid.Wait(0) // could have been os.WRUSAGE
if err != nil {
return
}
if ws.ExitStatus() != 0 {
err = os.NewError(cmd + " exited with status " + strconv.Itoa(ws.ExitStatus()))
}
return out, nil
}
开发者ID:andradeandrey,项目名称:goadmin,代码行数:31,代码来源:deps.go
示例5: run
// run runs the command argv, resolving argv[0] if necessary by searching $PATH.
// It provides input on standard input to the command.
func run(argv []string, input []byte) (out string, err os.Error) {
if len(argv) < 1 {
err = os.EINVAL
goto Error
}
prog, ok := lookPathCache[argv[0]]
if !ok {
prog, err = exec.LookPath(argv[0])
if err != nil {
goto Error
}
lookPathCache[argv[0]] = prog
}
cmd := exec.Command(prog, argv[1:]...)
if len(input) > 0 {
cmd.Stdin = bytes.NewBuffer(input)
}
bs, err := cmd.CombinedOutput()
if err == nil {
return string(bs), nil
}
Error:
err = &runError{dup(argv), err}
return
}
开发者ID:jnwhiteh,项目名称:go,代码行数:30,代码来源:main.go
最后编辑: kuteng 文档更新时间: 2021-08-23 19:14 作者:kuteng