當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Cmd.Wait方法代碼示例

本文整理匯總了Golang中exec.Cmd.Wait方法的典型用法代碼示例。如果您正苦於以下問題:Golang Cmd.Wait方法的具體用法?Golang Cmd.Wait怎麽用?Golang Cmd.Wait使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在exec.Cmd的用法示例。


在下文中一共展示了Cmd.Wait方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: run

// run runs the command argv, resolving argv[0] if necessary by searching $PATH.
// It provides input on standard input to the command.
func run(argv []string, input []byte) (out string, err os.Error) {
	if len(argv) < 1 {
		err = os.EINVAL
		goto Error
	}
	prog, ok := lookPathCache[argv[0]]
	if !ok {
		prog, err = exec.LookPath(argv[0])
		if err != nil {
			goto Error
		}
		lookPathCache[argv[0]] = prog
	}
	// fmt.Fprintf(os.Stderr, "%v\n", argv);
	var cmd *exec.Cmd
	if len(input) == 0 {
		cmd, err = exec.Run(prog, argv, os.Environ(), "", exec.DevNull, exec.Pipe, exec.MergeWithStdout)
		if err != nil {
			goto Error
		}
	} else {
		cmd, err = exec.Run(prog, argv, os.Environ(), "", exec.Pipe, exec.Pipe, exec.MergeWithStdout)
		if err != nil {
			goto Error
		}
		go func() {
			cmd.Stdin.Write(input)
			cmd.Stdin.Close()
		}()
	}
	defer cmd.Close()
	var buf bytes.Buffer
	_, err = io.Copy(&buf, cmd.Stdout)
	out = buf.String()
	if err != nil {
		cmd.Wait(0)
		goto Error
	}
	w, err := cmd.Wait(0)
	if err != nil {
		goto Error
	}
	if !w.Exited() || w.ExitStatus() != 0 {
		err = w
		goto Error
	}
	return

Error:
	err = &runError{copy(argv), err}
	return
}
開發者ID:ivanwyc,項目名稱:google-go,代碼行數:54,代碼來源:main.go

示例4: 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
}
開發者ID:ssrl,項目名稱:mgd,代碼行數:46,代碼來源:handy.go

示例5: run

func run(argv []string, stdin, stdout, stderr int) (out string, err os.Error) {

	if len(argv) < 1 {
		err = os.EINVAL
		goto Error
	}

	var cmd *exec.Cmd

	cmd, err = exec.Run(argv[0], argv, os.Environ(), "", stdin, stdout, stderr)

	if err != nil {
		goto Error
	}

	defer cmd.Close()

	var buf bytes.Buffer

	_, err = io.Copy(&buf, cmd.Stdout)
	out = buf.String()

	if err != nil {
		cmd.Wait(0)
		goto Error
	}

	w, err := cmd.Wait(0)

	if err != nil {
		goto Error
	}

	if !w.Exited() || w.ExitStatus() != 0 {
		err = w
		goto Error
	}

	return

Error:
	err = &runError{copy(argv), err}
	return
}
開發者ID:remogatto,項目名稱:makengo,代碼行數:44,代碼來源:system.go

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

示例7: link

func link(glfile string, opts []string, target string, ofile string, envv []string, dir string) (status syscall.WaitStatus, err os.Error) {
	arg := []string{glfile, "-o", target}
	for _, v := range opts {
		arg = append(arg, v)
	}
	arg = append(arg, ofile)
	fmt.Println("\t", arg)
	var cmd *exec.Cmd
	cmd, err = exec.Run(glfile, 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,代碼行數:23,代碼來源:promake.go


注:本文中的exec.Cmd.Wait方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。