Beispiel #1
0
func connectCmdsById(s *server, fromId, toId liblush.CmdId, streamname string) error {
	var stream liblush.OutStream
	var to, from liblush.Cmd
	from = s.session.GetCommand(fromId)
	if from == nil {
		return errors.New("unknown command in from")
	}
	switch streamname {
	case "stdout":
		stream = from.Stdout()
	case "stderr":
		stream = from.Stderr()
	default:
		return errors.New("unknown stream")
	}
	if toId == 0 {
		return disconnectStream(stream)
	}
	to = s.session.GetCommand(toId)
	if to == nil {
		return errors.New("unknown command in to")
	}
	if pipedcmd(stream) != nil {
		// not strictly necessary but makes for simpler API. service to the
		// user! because that is how we roll. EaaS.
		return errors.New("already connected to another command")
	}
	stream.SetListener(to.Stdin())
	return nil
}