当前位置: 首页>>代码示例>>Golang>>正文


Golang Cmd.StderrPipe方法代码示例

本文整理汇总了Golang中os/exec.Cmd.StderrPipe方法的典型用法代码示例。如果您正苦于以下问题:Golang Cmd.StderrPipe方法的具体用法?Golang Cmd.StderrPipe怎么用?Golang Cmd.StderrPipe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在os/exec.Cmd的用法示例。


在下文中一共展示了Cmd.StderrPipe方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: runCmdTeeStdio

func runCmdTeeStdio(cmd *exec.Cmd, stdOutPath, stdErrPath string) error {

	stdout, err := cmd.StdoutPipe()
	if err != nil {
		return fmt.Errorf("Error running caffe: StdoutPipe(). Err: %v", err)
	}

	stderr, err := cmd.StderrPipe()
	if err != nil {
		return fmt.Errorf("Error running caffe: StderrPipe(). Err: %v", err)
	}

	if err := cmd.Start(); err != nil {
		return fmt.Errorf("Error running caffe: cmd.Start(). Err: %v", err)
	}

	// read from stdout, stderr and write to temp files
	if err := saveCmdOutputToFiles(stdout, stderr, stdOutPath, stdErrPath); err != nil {
		return fmt.Errorf("Error running command: saveCmdOutput. Err: %v", err)
	}

	// wait for the command to complete
	runCommandErr := cmd.Wait()

	return runCommandErr

}
开发者ID:bryanyzhu,项目名称:elastic-thought,代码行数:27,代码来源:os_util.go

示例2: attachCmd

func attachCmd(cmd *exec.Cmd, stdout, stderr io.Writer, stdin io.Reader) (*sync.WaitGroup, error) {
	var wg sync.WaitGroup
	wg.Add(2)

	stdinIn, err := cmd.StdinPipe()
	if err != nil {
		return nil, err
	}
	stdoutOut, err := cmd.StdoutPipe()
	if err != nil {
		return nil, err
	}
	stderrOut, err := cmd.StderrPipe()
	if err != nil {
		return nil, err
	}

	go func() {
		io.Copy(stdinIn, stdin)
		stdinIn.Close()
	}()
	go func() {
		io.Copy(stdout, stdoutOut)
		wg.Done()
	}()
	go func() {
		io.Copy(stderr, stderrOut)
		wg.Done()
	}()

	return &wg, nil
}
开发者ID:r7kamura,项目名称:gitreceived,代码行数:32,代码来源:gitreceived.go

示例3: rsyncWebsocket

func rsyncWebsocket(cmd *exec.Cmd, conn *websocket.Conn) error {
	stdin, err := cmd.StdinPipe()
	if err != nil {
		return err
	}

	stdout, err := cmd.StdoutPipe()
	if err != nil {
		return err
	}

	stderr, err := cmd.StderrPipe()
	if err != nil {
		return err
	}

	if err := cmd.Start(); err != nil {
		return err
	}

	shared.WebsocketMirror(conn, stdin, stdout)
	data, err2 := ioutil.ReadAll(stderr)
	if err2 != nil {
		shared.Debugf("error reading rsync stderr: %s", err2)
		return err2
	}
	shared.Debugf("Stderr from rsync: %s", data)

	err = cmd.Wait()
	if err != nil {
		shared.Debugf("rsync recv error %s: %s", err, string(data))
	}

	return err
}
开发者ID:rockstar,项目名称:lxd,代码行数:35,代码来源:rsync.go

示例4: Run

// Run runs the command and returns a channel of output lines, errors and result of cmd.Wait
func Run(cmd *exec.Cmd, lines chan string) (error, error) {
	stdout, err := cmd.StdoutPipe()
	if err != nil {
		return nil, err
	}
	stderr, err := cmd.StderrPipe()
	if err != nil {
		return nil, err
	}

	err = cmd.Start()
	if err != nil {
		return nil, err
	}

	var wg sync.WaitGroup
	errCh := make(chan error, 2)
	wg.Add(2)
	go tailReader(bufio.NewReader(stdout), lines, errCh, &wg)
	go tailReader(bufio.NewReader(stderr), lines, errCh, &wg)
	wg.Wait()
	select {
	case err := <-errCh:
		return nil, err
	default:
	}
	return cmd.Wait(), nil
}
开发者ID:hpcloud,项目名称:run,代码行数:29,代码来源:run.go

示例5: gatherCmdOutput

func gatherCmdOutput(taskName string, cmd *exec.Cmd, eventsChan chan *types.Event) error {
	stdoutReader, err := cmd.StdoutPipe()
	if err != nil {
		return err
	}

	stderrReader, err := cmd.StderrPipe()
	if err != nil {
		return err
	}

	stdoutScanner := bufio.NewScanner(stdoutReader)
	stderrScanner := bufio.NewScanner(stderrReader)
	go func() {
		for stdoutScanner.Scan() {
			eventsChan <- types.NewOutputEvent(taskName, stdoutScanner.Bytes())
		}
	}()

	go func() {
		for stderrScanner.Scan() {
			eventsChan <- types.NewOutputEvent(taskName, stderrScanner.Bytes())
		}
	}()

	return nil
}
开发者ID:xsb,项目名称:dog,代码行数:27,代码来源:executor.go

示例6: connectOutputs

// Connect stderr/stdout of future child to logger and background copy jobs.
func connectOutputs(cmd *exec.Cmd, logger io.Writer, wg *sync.WaitGroup) error {
	if !opts.NoPipeStdout {
		stdout, err := cmd.StdoutPipe()
		if err != nil {
			return &StartupError{"connecting stdout", err}
		}
		if opts.WrapNagiosPlugin {
			firstbytes = NewCapWriter(8192)
			stdout := io.TeeReader(stdout, firstbytes)
			logStream(stdout, logger, wg)
		} else {
			logStream(stdout, logger, wg)
		}
	} else if opts.WrapNagiosPlugin {
		stdout, err := cmd.StdoutPipe()
		if err != nil {
			return &StartupError{"connecting stdout", err}
		}
		firstbytes = NewCapWriter(8192)
		logStream(stdout, firstbytes, wg)
	}

	if !opts.NoPipeStderr {
		stderr, err := cmd.StderrPipe()
		if err != nil {
			return &StartupError{"connecting stderr", err}
		}
		logStream(stderr, logger, wg)
	}
	return nil
}
开发者ID:Jimdo,项目名称:periodicnoise,代码行数:32,代码来源:log.go

示例7: ExecWithLog

func (c *EtcdAdapter) ExecWithLog(cmd *exec.Cmd, i int) {
	stdoutPipe, err := cmd.StdoutPipe()
	check(err)
	stderrPipe, err := cmd.StderrPipe()
	check(err)

	outFile, err := os.Create(fmt.Sprintf("/tmp/etcd_%d.out", i))
	check(err)
	errFile, err := os.Create(fmt.Sprintf("/tmp/etcd_%d.err", i))
	check(err)

	outWriter := bufio.NewWriter(outFile)
	errWriter := bufio.NewWriter(errFile)

	defer outWriter.Flush()
	defer errWriter.Flush()

	// Start the command
	err = cmd.Start()
	check(err)

	go io.Copy(outWriter, stdoutPipe)
	go io.Copy(errWriter, stderrPipe)

	c.launchProcess <- cmd.Process

	cmd.Wait()
}
开发者ID:rlayte,项目名称:teardown,代码行数:28,代码来源:etcd_cluster.go

示例8: execCmd

// execCmd executes the given command, and returns the stdout and stderr output.
// `logLineTitle` is the prefix for logging to the container log.
func execCmd(cmd *exec.Cmd, logLineTitle string) (string, string, error) {
	l := log.cmdLogger

	l.infoln(fmt.Sprintf("%s: Starting command: %v", logLineTitle, cmd.Args))

	stdoutPipe, err := cmd.StdoutPipe()
	if err != nil {
		return "", "", err
	}

	stderrPipe, err := cmd.StderrPipe()
	if err != nil {
		return "", "", err
	}

	// Save the command output while logging it.
	logFormatter := logLineTitle + " (%s): %%s"
	stdoutChan := logAndUpdate(*bufio.NewScanner(stdoutPipe), l,
		fmt.Sprintf(logFormatter, "stdout"))
	stderrChan := logAndUpdate(*bufio.NewScanner(stderrPipe), l,
		fmt.Sprintf(logFormatter, "stderr"))

	if err := cmd.Start(); err != nil {
		return "", "", err
	}

	stdout := <-stdoutChan
	stderr := <-stderrChan
	err = cmd.Wait()
	l.infoln(fmt.Sprintf("%s: Completed command: %v", logLineTitle, cmd.Args))
	return stdout, stderr, err
}
开发者ID:NetSys,项目名称:quilt,代码行数:34,代码来源:exec.go

示例9: NewExecutablePlugin

// Initialize a new ExecutablePlugin from path to executable and daemon mode (true or false)
func NewExecutablePlugin(a Arg, path string) (*ExecutablePlugin, error) {
	jsonArgs, err := json.Marshal(a)
	if err != nil {
		return nil, err
	}
	// Init the cmd
	cmd := new(exec.Cmd)
	cmd.Path = path
	cmd.Args = []string{path, string(jsonArgs)}
	// Link the stdout for response reading
	stdout, err := cmd.StdoutPipe()
	if err != nil {
		return nil, err
	}
	stderr, err := cmd.StderrPipe()
	if err != nil {
		return nil, err
	}
	// Init the ExecutablePlugin and return
	ePlugin := new(ExecutablePlugin)
	ePlugin.cmd = cmd
	ePlugin.stdout = stdout
	ePlugin.args = a
	ePlugin.stderr = stderr

	return ePlugin, nil
}
开发者ID:linearregression,项目名称:snap,代码行数:28,代码来源:execution.go

示例10: execTimeout

func execTimeout(timeout time.Duration, cmd *exec.Cmd) ([]byte, error) {
	stdout, err := cmd.StdoutPipe()
	if err != nil {
		return nil, err
	}
	stderr, err := cmd.StderrPipe()
	if err != nil {
		return nil, err
	}
	err = cmd.Start()
	if err != nil {
		return nil, err
	}

	b := bytes.NewBuffer([]byte{})
	go io.Copy(b, stdout)
	go io.Copy(b, stderr)

	_, timedOut, err := withtimeout.Do(timeout, func() (interface{}, error) {
		return nil, cmd.Wait()
	})
	if err != nil {
		if timedOut {
			go cmd.Process.Kill()
		}
		return nil, err
	}
	return b.Bytes(), nil
}
开发者ID:Christeefym,项目名称:lantern,代码行数:29,代码来源:upnp.go

示例11: ExecuteWithOutput

// ExecuteWithOutput executes a command. If logrus's verbosity level is set to
// debug, it will continuously output the command's output while it waits.
func ExecuteWithOutput(cmd *exec.Cmd) (outStr string, err error) {
	// connect to stdout and stderr for filtering purposes
	errPipe, err := cmd.StderrPipe()
	if err != nil {
		log.WithFields(log.Fields{
			"cmd": cmd.Args,
		}).Fatal("Couldn't connect to command's stderr")
	}
	outPipe, err := cmd.StdoutPipe()
	if err != nil {
		log.WithFields(log.Fields{
			"cmd": cmd.Args,
		}).Fatal("Couldn't connect to command's stdout")
	}
	_ = bufio.NewReader(errPipe)
	outReader := bufio.NewReader(outPipe)

	// start the command and filter the output
	if err = cmd.Start(); err != nil {
		return "", err
	}
	outScanner := bufio.NewScanner(outReader)
	for outScanner.Scan() {
		outStr += outScanner.Text() + "\n"
		if log.GetLevel() == log.DebugLevel {
			fmt.Println(outScanner.Text())
		}
	}
	err = cmd.Wait()
	return outStr, err
}
开发者ID:lokinell,项目名称:microservices-infrastructure,代码行数:33,代码来源:mi-deploy.go

示例12: pipeCommandToFile

func pipeCommandToFile(cmd *exec.Cmd, path string) error {
	file, err := os.Create(path)
	if err != nil {
		return err
	}
	defer file.Close()
	stdout, err := cmd.StdoutPipe()
	if err != nil {
		return err
	}
	stderr, err := cmd.StderrPipe()
	if err != nil {
		return err
	}

	err = cmd.Start()
	if err != nil {
		return err
	}

	go io.Copy(os.Stdout, stderr)

	io.Copy(file, stdout)
	return cmd.Wait()
}
开发者ID:GlenKelley,项目名称:dev,代码行数:25,代码来源:build.go

示例13: execWithOutput

func execWithOutput(cmd *exec.Cmd, outWriter io.Writer, errWriter io.Writer) (err error) {
	plog.Info(map[string]interface{}{
		"event": "exec_command",
		"cmd":   fmt.Sprintf("[%s] %s %v", cmd.Dir, cmd.Path, cmd.Args),
	})

	stdout, err := cmd.StdoutPipe()
	if err != nil {
		return
	}
	stderr, err := cmd.StderrPipe()
	if err != nil {
		return
	}
	err = cmd.Start()
	if err != nil {
		return
	}
	go io.Copy(outWriter, stdout)
	defer stdout.Close()

	go io.Copy(errWriter, stderr)
	defer stderr.Close()

	err = cmd.Wait()
	return
}
开发者ID:minefold,项目名称:pinky,代码行数:27,代码来源:server.go

示例14: preprocessFile

func (c *ClientServer) preprocessFile(cmd *exec.Cmd, f io.Reader) ([]byte, error) {
	if stdout, err := cmd.StdoutPipe(); err == nil {
		if stdin, err := cmd.StdinPipe(); err == nil {
			if stderr, err := cmd.StderrPipe(); err == nil {
				if err := cmd.Start(); err == nil {
					if b, err := ioutil.ReadAll(f); err == nil {
						stdin.Write(b)
						stdin.Close()
						out, _ := ioutil.ReadAll(stdout)
						stde, _ := ioutil.ReadAll(stderr)
						if e := cmd.Wait(); e == nil {
							return out, nil
						} else {
							return stde, fmt.Errorf("Preprocessor failed.")
						}
					} else {
						return nil, err
					}
				} else {
					return nil, err
				}
			} else {
				return nil, err
			}
		} else {
			return nil, err
		}
	} else {
		return nil, err
	}
}
开发者ID:nemothekid,项目名称:tinybusters,代码行数:31,代码来源:client.go

示例15: start

func start(c *exec.Cmd) (io.ReadCloser, io.WriteCloser, error) {
	c.SysProcAttr = &syscall.SysProcAttr{}
	//c.SysProcAttr.CreationFlags = 16 // CREATE_NEW_CONSOLE

	stdin, err := c.StdinPipe()

	if err != nil {
		return nil, nil, err
	}

	stdout, err := c.StdoutPipe()

	if err != nil {
		return nil, nil, err
	}

	stderr, err := c.StderrPipe()

	if err != nil {
		return nil, nil, err
	}

	t := &term{}
	t.cmd = c
	t.stderr = stderr
	t.stdout = stdout
	t.stdin = stdin

	err = t.start()
	if err != nil {
		return nil, nil, err
	}

	return t, t, nil
}
开发者ID:XQYCHJ,项目名称:godev,代码行数:35,代码来源:terminal-windows.go


注:本文中的os/exec.Cmd.StderrPipe方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。