本文整理匯總了Golang中exec.Cmd.Stderr方法的典型用法代碼示例。如果您正苦於以下問題:Golang Cmd.Stderr方法的具體用法?Golang Cmd.Stderr怎麽用?Golang Cmd.Stderr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類exec.Cmd
的用法示例。
在下文中一共展示了Cmd.Stderr方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}
示例2: 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
}
示例3: StdExecve
func StdExecve(argv []string, stopOnTrouble bool) bool {
var err os.Error
var cmd *exec.Cmd
switch len(argv) {
case 0:
if stopOnTrouble {
log.Fatalf("[ERROR] len(argv) == 0\n")
}
return false
case 1:
cmd = exec.Command(argv[0])
default:
cmd = exec.Command(argv[0], argv[1:]...)
}
// pass-through
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
err = cmd.Start()
if err != nil {
if stopOnTrouble {
log.Fatalf("[ERROR] %s\n", err)
} else {
log.Printf("[ERROR] %s\n", err)
return false
}
}
err = cmd.Wait()
if err != nil {
if stopOnTrouble {
log.Fatalf("[ERROR] %s\n", err)
} else {
log.Printf("[ERROR] %s\n", err)
return false
}
}
return true
}
示例4: set_exec
/*
Set up a command to use os standard in/out/err
*/
func set_exec(c *exec.Cmd) {
c.Stdout = os.Stdout
c.Stdin = os.Stdin
c.Stderr = os.Stderr
}