本文整理汇总了Golang中github.com/juju/utils/exec.ExecResponse.Stdout方法的典型用法代码示例。如果您正苦于以下问题:Golang ExecResponse.Stdout方法的具体用法?Golang ExecResponse.Stdout怎么用?Golang ExecResponse.Stdout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/utils/exec.ExecResponse
的用法示例。
在下文中一共展示了ExecResponse.Stdout方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Main
// Main runs the Command specified by req, and fills in resp. A single command
// is run at a time.
func (j *Jujuc) Main(req Request, resp *exec.ExecResponse) error {
if req.CommandName == "" {
return badReqErrorf("command not specified")
}
if !filepath.IsAbs(req.Dir) {
return badReqErrorf("Dir is not absolute")
}
c, err := j.getCmd(req.ContextId, req.CommandName)
if err != nil {
return badReqErrorf("%s", err)
}
var stdin, stdout, stderr bytes.Buffer
ctx := &cmd.Context{
Dir: req.Dir,
Stdin: &stdin,
Stdout: &stdout,
Stderr: &stderr,
}
j.mu.Lock()
defer j.mu.Unlock()
logger.Infof("running hook tool %q %q", req.CommandName, req.Args)
logger.Debugf("hook context id %q; dir %q", req.ContextId, req.Dir)
resp.Code = cmd.Main(c, ctx, req.Args)
resp.Stdout = stdout.Bytes()
resp.Stderr = stderr.Bytes()
return nil
}
示例2: Main
// Main runs the Command specified by req, and fills in resp. A single command
// is run at a time.
func (j *Jujuc) Main(req Request, resp *exec.ExecResponse) error {
if req.CommandName == "" {
return badReqErrorf("command not specified")
}
if !filepath.IsAbs(req.Dir) {
return badReqErrorf("Dir is not absolute")
}
c, err := j.getCmd(req.ContextId, req.CommandName)
if err != nil {
return badReqErrorf("%s", err)
}
var stdin io.Reader
if req.StdinSet {
stdin = bytes.NewReader(req.Stdin)
} else {
// noStdinReader will error with ErrNoStdin
// if its Read method is called.
stdin = noStdinReader{}
}
var stdout, stderr bytes.Buffer
ctx := &cmd.Context{
Dir: req.Dir,
Stdin: stdin,
Stdout: &stdout,
Stderr: &stderr,
}
j.mu.Lock()
defer j.mu.Unlock()
// Beware, reducing the log level of the following line will lead
// to passwords leaking if passed as args.
logger.Tracef("running hook tool %q %q", req.CommandName, req.Args)
logger.Tracef("running hook tool %q", req.CommandName)
logger.Debugf("hook context id %q; dir %q", req.ContextId, req.Dir)
wrapper := &cmdWrapper{c, nil}
resp.Code = cmd.Main(wrapper, ctx, req.Args)
if errors.Cause(wrapper.err) == ErrNoStdin {
return ErrNoStdin
}
resp.Stdout = stdout.Bytes()
resp.Stderr = stderr.Bytes()
return nil
}