Example #1
0
func (c *qCmd) start(txt string) error {
	c.Lock()
	if c.ctx != nil {
		c.Unlock()
		return fmt.Errorf("%s: one cmd is enough", c)
	}
	c.txt = txt
	var in chan interface{}
	if c.in.Len() > 0 {
		c.in.c = make(chan interface{}, len(c.in.msgs))
		for _, m := range c.in.msgs {
			c.in.c <- m
		}
		close(c.in.c)
		in = c.in.c
	}
	outfn := func(c *qCmd, io *qIO, outc chan interface{}) {
		for m := range outc {
			c.Lock()
			io.addOut(m)
			c.Unlock()
		}
		io.eof = true
		io.wakeup()
	}
	out := make(chan interface{})
	go outfn(c, c.out, out)
	err := make(chan interface{})
	go outfn(c, c.err, err)
	c.e.runc <- func() {
		c.ctx = app.Go(func() {
			c.Unlock()
			app.DupDot()
			app.DupEnv()
			app.NewIO(nil)
			app.SetIO(in, 0)
			app.SetIO(out, 1)
			app.SetIO(err, 2)
			ql.Run()
		}, "ql", "-c", c.txt)
	}
	return nil
}
Example #2
0
// runs here
func runDup(x *xEnv, argv ...string) error {
	opts := opt.New("dup")
	app.Dprintf("dup %v\n", argv)
	args, err := opts.Parse(argv)
	if err != nil {
		opts.Usage()
		return dbg.ErrUsage
	}
	for _, arg := range args {
		switch arg {
		case "ns":
			app.DupNS()
		case "io":
			app.DupIO()
		case "env":
			app.DupEnv()
		case "dot":
			app.DupDot()
		default:
			app.Warn("unknown resource '%s'", arg)
		}
	}
	return nil
}