Exemplo n.º 1
0
func RunChild(argv0 string, argv []string, envv []string, dir string, stderr *os.File) (*Child, error) {

	cmd := exec.Command(argv0)
	cmd.Args = argv
	cmd.Env = envv
	cmd.Dir = dir
	cmd.Stderr = stderr

	parentW, err := cmd.StdinPipe()
	if err != nil {
		return nil, err
	}
	parentR, err := cmd.StdoutPipe()
	if err != nil {
		return nil, err
	}

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

	parent := moreio.NewReadWriteCloser(parentR, parentW)
	client := rpc.NewClient(parent)
	c := Child{
		cmd:    cmd,
		client: client,
	}
	return &c, nil
}
Exemplo n.º 2
0
func child() {
	logger := log.New(os.Stderr, "child: ", log.Ldate|log.Ltime)

	logger.Println("child mode")
	echo := new(Echo)
	rpc.Register(echo)
	m := moreio.NewReadWriteCloser(os.Stdin, os.Stdout)
	rpc.ServeConn(m)
}