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


Golang os.Wait函数代码示例

本文整理汇总了Golang中os.Wait函数的典型用法代码示例。如果您正苦于以下问题:Golang Wait函数的具体用法?Golang Wait怎么用?Golang Wait使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: git_from_net

func git_from_net(url string) string {
	var args [3]string
	args[0] = "git"
	args[1] = "clone"
	args[2] = url
	var fds []*os.File = new([3]*os.File)
	fds[0] = os.Stdin
	fds[1] = os.Stdout
	fds[2] = os.Stderr

	_, str := path.Split(url)
	name := strings.Split(str, ".", -1)[0]
	var git_path string

	switch os.Getenv("GOOS") {
	case "darwin":
		git_path = "/usr/local/git/bin/git"
		break
	case "linux":
		git_path = "/opt/local/bin/git"
		break
	}

	/* Replace this with git's full path, or use a shell, and then call git in the args */
	pid, err := os.ForkExec(git_path, &args, os.Envs, os.Getenv("GOROOT")+"/src/pkg/", fds)
	if err != nil {
		log.Exit(err)
	}

	os.Wait(pid, 0)

	return string(os.Getenv("GOROOT") + "/src/pkg/" + name)
}
开发者ID:ox,项目名称:GoStones,代码行数:33,代码来源:main.go

示例2: GetOutput

// Return the output from running the given command
func GetOutput(args []string) (output string, error os.Error) {
	read_pipe, write_pipe, err := os.Pipe()
	if err != nil {
		goto Error
	}
	defer read_pipe.Close()
	pid, err := os.ForkExec(args[0], args, os.Environ(), ".", []*os.File{nil, write_pipe, nil})
	if err != nil {
		write_pipe.Close()
		goto Error
	}
	_, err = os.Wait(pid, 0)
	write_pipe.Close()
	if err != nil {
		goto Error
	}
	buffer := &bytes.Buffer{}
	_, err = io.Copy(buffer, read_pipe)
	if err != nil {
		goto Error
	}
	output = buffer.String()
	return output, nil
Error:
	return "", &CommandError{args[0], args}
}
开发者ID:strogo,项目名称:ampify,代码行数:27,代码来源:command.go

示例3: DateServer

// exec a program, redirecting output
func DateServer(c *http.Conn, req *http.Request) {
	c.SetHeader("content-type", "text/plain; charset=utf-8")
	r, w, err := os.Pipe()
	if err != nil {
		fmt.Fprintf(c, "pipe: %s\n", err)
		return
	}
	pid, err := os.ForkExec("/bin/date", []string{"date"}, os.Environ(), "", []*os.File{nil, w, w})
	defer r.Close()
	w.Close()
	if err != nil {
		fmt.Fprintf(c, "fork/exec: %s\n", err)
		return
	}
	io.Copy(c, r)
	wait, err := os.Wait(pid, 0)
	if err != nil {
		fmt.Fprintf(c, "wait: %s\n", err)
		return
	}
	if !wait.Exited() || wait.ExitStatus() != 0 {
		fmt.Fprintf(c, "date: %v\n", wait)
		return
	}
}
开发者ID:8l,项目名称:go-learn,代码行数:26,代码来源:triv.go

示例4: wait

// wait waits for a wait event from this thread and sends it on the
// debug events channel for this thread's process.  This should be
// started in its own goroutine when the attached thread enters a
// running state.  The goroutine will exit as soon as it sends a debug
// event.
func (t *thread) wait() {
	for {
		var ev debugEvent
		ev.t = t
		t.logTrace("beginning wait")
		ev.Waitmsg, ev.err = os.Wait(t.tid, syscall.WALL)
		if ev.err == nil && ev.Pid != t.tid {
			panic(fmt.Sprint("Wait returned pid ", ev.Pid, " wanted ", t.tid))
		}
		if ev.StopSignal() == syscall.SIGSTOP && t.ignoreNextSigstop {
			// Spurious SIGSTOP.  See Thread.Stop().
			t.ignoreNextSigstop = false
			err := t.ptraceCont()
			if err == nil {
				continue
			}
			// If we failed to continue, just let
			// the stop go through so we can
			// update the thread's state.
		}
		if !<-t.proc.ready {
			// The monitor exited
			break
		}
		t.proc.debugEvents <- &ev
		break
	}
}
开发者ID:IntegerCompany,项目名称:linaro-android-gcc,代码行数:33,代码来源:proc_linux.go

示例5: Serve

func Serve(conn net.Conn) {
	defer conn.Close()
	tty, pid, err := term.ForkPty(
		"/bin/login",
		[]string{"/bin/login"},
		term.DefaultAttributes(),
		term.NewWindowSize(80, 25))

	if err != nil {
		fmt.Fprintf(os.Stderr, "ForkExecPty failed: %v\n", err)
		return
	}

	defer os.Wait(pid, 0)
	defer syscall.Kill(pid, 9)

	running := true

	go func() {
		buffer := make([]byte, 64)
		for n, e := conn.Read(buffer); e == nil && running; n, e = conn.Read(buffer) {
			tty.Write(buffer[:n])
		}
		running = false
	}()

	go func() {
		buffer := make([]byte, 64)
		var n int
		var e os.Error
		for n, e = tty.Read(buffer); e == nil && running; n, e = tty.Read(buffer) {
			conn.Write(buffer[:n])
		}
		running = false
	}()

	tick := time.NewTicker(1e9)
	for running {
		select {
		case <-tick.C:
			msg, err := os.Wait(pid, os.WNOHANG)
			if err == nil && msg.Pid == pid {
				running = false
			}
		}
	}
}
开发者ID:krockot,项目名称:goterm,代码行数:47,代码来源:shelld.go

示例6: wait

func (mon *monitor) wait(pid int, e exiteder) {
	w, err := os.Wait(pid, 0)
	if err != nil {
		mon.logger.Println(err)
		return
	}

	mon.exitCh <- exit{e, w}
}
开发者ID:andradeandrey,项目名称:doozer,代码行数:9,代码来源:mon.go

示例7: runSystemCommand

func runSystemCommand(argv []string, dir string) string {
	lookedPath, _ := exec.LookPath(argv[0])
	r, w, _ := os.Pipe()
	pid, _ := os.ForkExec(lookedPath, argv, nil, dir, []*os.File{nil, w, w})
	w.Close()
	os.Wait(pid, 0)
	var b bytes.Buffer
	io.Copy(&b, r)
	return b.String()
}
开发者ID:cc-syncsuite,项目名称:piggydemon,代码行数:10,代码来源:piggydemon.go

示例8: Wait

// Wait waits for the running command p,
// returning the Waitmsg returned by os.Wait and an error.
// The options are passed through to os.Wait.
// Setting options to 0 waits for p to exit;
// other options cause Wait to return for other
// process events; see package os for details.
func (p *Cmd) Wait(options int) (*os.Waitmsg, os.Error) {
	if p.Pid <= 0 {
		return nil, os.ErrorString("exec: invalid use of Cmd.Wait")
	}
	w, err := os.Wait(p.Pid, options)
	if w != nil && (w.Exited() || w.Signaled()) {
		p.Pid = -1
	}
	return w, err
}
开发者ID:IntegerCompany,项目名称:linaro-android-gcc,代码行数:16,代码来源:exec.go

示例9: stage_check

func stage_check(cpid int, err os.Error, stage string) {
	if err == nil {
		lolf, _ := os.Wait(cpid, 0)
		if lolf.ExitStatus() != 0 {
			fmt.Printf("Failed to %s.\n", stage)
			os.Exit(lolf.ExitStatus())
		}
	} else {
		fmt.Println(err)
		os.Exit(1)
	}
}
开发者ID:stiletto,项目名称:goscript,代码行数:12,代码来源:goscript.go

示例10: TestTrue

func TestTrue(t *testing.T) {
	if !hasProc() {
		return
	}

	cx := Context{}
	pid, err := cx.ForkExec("/bin/true", nil)
	assert.Equal(t, nil, err)
	assert.T(t, pid > 0)
	w, err := os.Wait(pid, 0)
	assert.Equal(t, true, w.Exited())
	assert.Equal(t, 0, w.ExitStatus())
}
开发者ID:andradeandrey,项目名称:doozer,代码行数:13,代码来源:exec_test.go

示例11: UnmountFuse

func UnmountFuse(mountpoint string) (err os.Error) {
	var pid int
	fmt.Println("Unmounting", mountpoint, "...")
	for i := 0; i < len(paths); i++ {
		var args []string = []string{paths[i], "-u", mountpoint}
		pid, err = os.ForkExec(paths[i], args, []string{}, "",
			[]*os.File{os.Stdin, os.Stdout, os.Stderr})
		if err == nil {
			os.Wait(pid, 0)
			return err
		}
	}
	return err
}
开发者ID:droundy,项目名称:myfs,代码行数:14,代码来源:main.go

示例12: privilegedUnmount

func privilegedUnmount(mountPoint string) error {
	dir, _ := filepath.Split(mountPoint)
	proc, err := os.StartProcess(umountBinary,
		[]string{umountBinary, mountPoint},
		&os.ProcAttr{Dir: dir, Files: []*os.File{nil, nil, os.Stderr}})
	if err != nil {
		return err
	}
	w, err := os.Wait(proc.Pid, 0)
	if w.ExitStatus() != 0 {
		return fmt.Errorf("umount exited with code %d\n", w.ExitStatus())
	}
	return err
}
开发者ID:taruti,项目名称:go-fuse,代码行数:14,代码来源:mount.go

示例13: main

func main() {
	checkArgs()
	output, absError := abspath(*outputDir)
	if absError != nil {
		showErrorAndQuit(absError.String(), -1)
	}

	programPath, programError := getProgramPath()
	if programError != nil {
		showErrorAndQuit(programError.String(), -1)
	}

	erlPath, pathError := exec.LookPath("erl")

	if pathError != nil {
		showErrorAndQuit("Can't find erl program", -1)
	}

	head := []string{erlPath, "-run", "efene", "main", *outputType, output}
	tail := []string{"-run", "init", "stop", "-noshell"}
	start := len(head) + flag.NArg()
	args := make([]string, len(head)+len(tail)+flag.NArg())

	for i := 0; i < len(head); i++ {
		args[i] = head[i]
	}

	for i := len(head); i < len(head)+flag.NArg(); i++ {
		args[i], _ = abspath(flag.Arg(i - len(head)))
	}

	for i := start; i < start+len(tail); i++ {
		args[i] = tail[i-start]
	}

	if *verbose {
		fmt.Println("cd " + programPath)
		fmt.Print(erlPath + " ")
		printArray(args, true)
	}

	pid, error := os.ForkExec(erlPath, args, os.Environ(), programPath, []*os.File{os.Stdin, os.Stdout, os.Stderr})

	if error != nil {
		showErrorAndQuit(error.String(), -1)
	}

	os.Wait(pid, 0)
}
开发者ID:essiene,项目名称:efene,代码行数:49,代码来源:fnc.go

示例14: run

// run runs the command argv, feeding in stdin on standard input.
// It returns the output to standard output and standard error.
// ok indicates whether the command exited successfully.
func run(stdin []byte, argv []string) (stdout, stderr []byte, ok bool) {
	cmd, err := exec.LookPath(argv[0]);
	if err != nil {
		fatal("exec %s: %s", argv[0], err);
	}
	r0, w0, err := os.Pipe();
	if err != nil {
		fatal("%s", err);
	}
	r1, w1, err := os.Pipe();
	if err != nil {
		fatal("%s", err);
	}
	r2, w2, err := os.Pipe();
	if err != nil {
		fatal("%s", err);
	}
	pid, err := os.ForkExec(cmd, argv, os.Environ(), "", []*os.File{r0, w1, w2});
	if err != nil {
		fatal("%s", err);
	}
	r0.Close();
	w1.Close();
	w2.Close();
	c := make(chan bool);
	go func() {
		w0.Write(stdin);
		w0.Close();
		c <- true;
	}();
	var xstdout []byte;	// TODO(rsc): delete after 6g can take address of out parameter
	go func() {
		xstdout, _ = io.ReadAll(r1);
		r1.Close();
		c <- true;
	}();
	stderr, _ = io.ReadAll(r2);
	r2.Close();
	<-c;
	<-c;
	stdout = xstdout;

	w, err := os.Wait(pid, 0);
	if err != nil {
		fatal("%s", err);
	}
	ok = w.Exited() && w.ExitStatus() == 0;
	return;
}
开发者ID:8l,项目名称:go-learn,代码行数:52,代码来源:util.go

示例15: run

// run runs the command argv, feeding in stdin on standard input.
// It returns the output to standard output and standard error.
// ok indicates whether the command exited successfully.
func run(stdin []byte, argv []string) (stdout, stderr []byte, ok bool) {
	cmd, err := exec.LookPath(argv[0])
	if err != nil {
		fatal("exec %s: %s", argv[0], err)
	}
	r0, w0, err := os.Pipe()
	if err != nil {
		fatal("%s", err)
	}
	r1, w1, err := os.Pipe()
	if err != nil {
		fatal("%s", err)
	}
	r2, w2, err := os.Pipe()
	if err != nil {
		fatal("%s", err)
	}
	pid, err := os.ForkExec(cmd, argv, os.Environ(), "", []*os.File{r0, w1, w2})
	if err != nil {
		fatal("%s", err)
	}
	r0.Close()
	w1.Close()
	w2.Close()
	c := make(chan bool)
	go func() {
		w0.Write(stdin)
		w0.Close()
		c <- true
	}()
	var xstdout []byte // TODO(rsc): delete after 6g can take address of out parameter
	go func() {
		xstdout, _ = ioutil.ReadAll(r1)
		r1.Close()
		c <- true
	}()
	stderr, _ = ioutil.ReadAll(r2)
	r2.Close()
	<-c
	<-c
	stdout = xstdout

	w, err := os.Wait(pid, 0)
	if err != nil {
		fatal("%s", err)
	}
	ok = w.Exited() && w.ExitStatus() == 0
	return
}
开发者ID:ivanwyc,项目名称:google-go,代码行数:52,代码来源:util.go


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