本文整理汇总了Golang中exec.Cmd类的典型用法代码示例。如果您正苦于以下问题:Golang Cmd类的具体用法?Golang Cmd怎么用?Golang Cmd使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Cmd类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: RunExternalDump
func RunExternalDump(cmd, wd string, argv []string, dump io.Writer) (err os.Error) {
var p *exec.Cmd
p, err = exec.Run(cmd, argv, nil, wd, exec.PassThrough, exec.Pipe, exec.PassThrough)
if err != nil {
return
}
if p != nil {
src := p.Stdout
buffer := make([]byte, 1024)
for {
n, cpErr := src.Read(buffer)
if cpErr != nil {
break
}
_, cpErr = dump.Write(buffer[0:n])
if cpErr != nil {
break
}
}
var wmsg *os.Waitmsg
wmsg, err = p.Wait(0)
if wmsg.ExitStatus() != 0 {
err = os.NewError(fmt.Sprintf("%v: %s\n", argv, wmsg.String()))
return
}
if err != nil {
return
}
}
return
}
开发者ID:clarencethecat,项目名称:gbide,代码行数:32,代码来源:gbrun.go
示例2: build
func build(gcfile string, opts []string, proFileName string, files []string, envv []string, dir string) (status syscall.WaitStatus, err os.Error) {
arg := []string{gcfile, "-o", proFileName}
for _, v := range opts {
arg = append(arg, v)
}
for _, v := range files {
arg = append(arg, string(v))
}
fmt.Println("\t", arg)
var cmd *exec.Cmd
cmd, err = exec.Run(gcfile, arg[:], envv[:], dir, 0, 1, 2)
if err != nil {
fmt.Printf("Error, %s", err)
return
}
defer cmd.Close()
var wait *os.Waitmsg
wait, err = cmd.Wait(0)
if err != nil {
fmt.Printf("Error, %s", err)
return
}
status = wait.WaitStatus
return
}
开发者ID:gaopeng1106,项目名称:liteide.liteide,代码行数:25,代码来源:promake.go
示例3: RunWithEnvAndWd
func RunWithEnvAndWd(command string, args []string, env []string, wd string) (proc *exec.Cmd, err os.Error) {
//log.Println(command, args)
//hho := exec.PassThrough
args = prepend(args, command)
env = mergeEnv(os.Environ(), env)
binpath, err := findCmd(findEnv(env, "PATH"), command)
if err != nil {
return nil, err
}
cmd := new(exec.Cmd)
cmd.Path = binpath
cmd.Args = args
cmd.Env = env
cmd.Dir = wd
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
err = cmd.Start()
if err != nil {
log.Print("Error running command ", command, ": ", err, "\n")
return nil, err
}
return cmd, nil
}
开发者ID:Epictetus,项目名称:wfdr,代码行数:26,代码来源:osutil.go
示例4: RunExternalAndStdout
func RunExternalAndStdout(cmd, wd string, argv []string) (stdout []byte, err os.Error) {
argv = SplitArgs(argv)
var c *exec.Cmd
if len(argv) > 0 {
c = exec.Command(cmd, argv...)
} else {
c = exec.Command(cmd)
}
c.Dir = wd
c.Env = os.Environ()
bStdout := bytes.NewBuffer(nil)
bStderr := bytes.NewBuffer(nil)
c.Stdout = bStdout
c.Stderr = bStderr
err = c.Run()
if wmsg, ok := err.(*os.Waitmsg); ok {
if wmsg.ExitStatus() != 0 {
err = os.NewError(fmt.Sprintf("command: %s %v\n%s\n", cmd, argv, bStderr.String()))
} else {
err = nil
}
} else {
stdout = bStdout.Bytes()
}
return
}
开发者ID:wb253,项目名称:go-gb,代码行数:29,代码来源:runext.go
示例5: pack
func pack(pkfile string, target string, ofile string, envv []string, dir string) (status syscall.WaitStatus, err os.Error) {
arg := []string{pkfile, "grc", target, ofile}
fmt.Println("\t", arg)
var cmd *exec.Cmd
cmd, err = exec.Run(pkfile, arg[:], envv[:], dir, 0, 1, 2)
if err != nil {
fmt.Printf("Error, %s", err)
return
}
defer cmd.Close()
var wait *os.Waitmsg
wait, err = cmd.Wait(0)
if err != nil {
fmt.Printf("Error, %s", err)
return
}
status = wait.WaitStatus
return
}
开发者ID:gaopeng1106,项目名称:liteide.liteide,代码行数:19,代码来源:promake.go
最后编辑: kuteng 文档更新时间: 2021-08-23 19:14 作者:kuteng