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


Golang Cmd.StdoutPipe方法代码示例

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


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

示例1: 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

示例2: 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

示例3: RunCommandWithStdoutStderr

// RunCommandWithStdoutStderr execs a command and returns its output.
func RunCommandWithStdoutStderr(cmd *exec.Cmd) (bytes.Buffer, bytes.Buffer, error) {
	var stdout, stderr bytes.Buffer
	stderrPipe, err := cmd.StderrPipe()
	stdoutPipe, err := cmd.StdoutPipe()

	cmd.Env = os.Environ()
	if err != nil {
		fmt.Println("error at io pipes")
	}

	err = cmd.Start()
	if err != nil {
		fmt.Println("error at command start")
	}

	go func() {
		streamOutput(stdoutPipe, &stdout, os.Stdout)
	}()
	go func() {
		streamOutput(stderrPipe, &stderr, os.Stderr)
	}()
	err = cmd.Wait()
	if err != nil {
		fmt.Println("error at command wait")
	}
	return stdout, stderr, err
}
开发者ID:helgi,项目名称:pkg,代码行数:28,代码来源:utils.go

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: printlog

func printlog(c2 *exec.Cmd) {

	stdout, err := c2.StdoutPipe()

	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	if err := c2.Start(); err != nil {
		fmt.Println("Command  error:", err.Error())
		os.Exit(1)
	}
	in := bufio.NewScanner(stdout)
	fmt.Println(in)

	for in.Scan() {

		fmt.Println(in.Text())

	}
	if err := in.Err(); err != nil {
		fmt.Println("Err:", err.Error())
		os.Exit(1)
	}
}
开发者ID:eshujiushiwo,项目名称:eshu-devops,代码行数:26,代码来源:cjs1.go

示例9: attachCmd

func attachCmd(cmd *exec.Cmd, ch ssh.Channel) (*sync.WaitGroup, error) {
	var wg sync.WaitGroup
	wg.Add(3)

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

	go func() {
		defer wg.Done()
		io.Copy(stdin, ch)
	}()

	go func() {
		defer wg.Done()
		io.Copy(ch.Stderr(), stderr)
	}()

	go func() {
		defer wg.Done()
		io.Copy(ch, stdout)
	}()

	return &wg, nil
}
开发者ID:robinmonjo,项目名称:dockpack,代码行数:34,代码来源:server.go

示例10: 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

示例11: WrapinMKV

func WrapinMKV(uuidpath string, audioin chan []byte, audio bool) {
	var ffmpeg *exec.Cmd
	if audio {
		ffmpeg = exec.Command("ffmpeg", "-f", "mjpeg", "-i", uuidpath, "-f", "s32be", "-ac", "2", "-ar", "44100", "-i", "pipe:0", "-f", "matroska", "-codec", "copy", "pipe:1")
	} else {
		ffmpeg = exec.Command("ffmpeg", "-f", "mjpeg", "-i", uuidpath, "-f", "matroska", "-codec", "copy", "pipe:1")
	}
	ffmpegstdout, err := ffmpeg.StdoutPipe()
	if err != nil {
		log.Fatalf("Unable to setup pipes for ffmpeg (stdout)")
	}
	ffmpeg.Stderr = os.Stderr

	audiofile, err := ffmpeg.StdinPipe()

	go DumpChanToFile(audioin, audiofile)

	ffmpeg.Start()

	for {
		_, err := io.Copy(os.Stdout, ffmpegstdout)
		if err != nil {
			log.Fatalf("unable to read to stdout: %s", err.Error())
		}
	}
}
开发者ID:CodeMason,项目名称:de-ip-hdmi,代码行数:26,代码来源:main.go

示例12: 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

示例13: callCont

func callCont(c *exec.Cmd, cont func(io.Reader) error) error {
	_, callerFile, callerLine, _ := runtime.Caller(1)
	log.Printf("%15s:%.3d -> %s", path.Base(callerFile), callerLine, strings.Join(c.Args, " "))
	var reader io.Reader
	var err error
	if cont != nil {
		reader, err = c.StdoutPipe()
		if err != nil {
			return err
		}
	}
	stderr, err := c.StderrPipe()
	if err != nil {
		return err
	}
	if err = c.Start(); err != nil {
		return err
	}
	if cont != nil {
		if err = cont(reader); err != nil {
			return err
		}
	}
	buffer := bytes.NewBuffer(nil)
	buffer.ReadFrom(stderr)
	if buffer.Len() != 0 {
		log.Print("Command had output on stderr.\n Cmd: ", strings.Join(c.Args, " "), "\nstderr: ", buffer)
	}
	return c.Wait()
}
开发者ID:bboalimoe,项目名称:pachyderm,代码行数:30,代码来源:shell.go

示例14: 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

示例15: ExecGenCmd

func ExecGenCmd(args []string) (string, error) {
	var cmd *exec.Cmd

	argsNew := make([]string, len(args)+1)
	argsNew[0] = "generate"
	for i, a := range args {
		argsNew[i+1] = a
	}

	cmd = exec.Command("./ocitools", argsNew...)
	cmd.Dir = "./plugins"
	// cmd.stdin = os.Stdin
	stderr, err := cmd.StderrPipe()
	if err != nil {
		log.Fatal("stderr err %v", err)
	}

	stdout, err := cmd.StdoutPipe()
	if err != nil {
		log.Fatalf("stdout err %v", err)
	}

	var retStr string
	err = cmd.Start()
	if err != nil {
		retb, _ := ioutil.ReadAll(stderr)
		retStr = string(retb)
		// stdoutReader.ReadRune()
	} else {
		retb, _ := ioutil.ReadAll(stdout)
		retStr = string(retb)
	}

	return retStr, err
}
开发者ID:pombredanne,项目名称:oct,代码行数:35,代码来源:cmd.go


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