Beispiel #1
0
func (s SubSubshell) Sub(scp *variables.Scope) (returnString string) {
	logex.Debug("Substituting shell")
	defer func() {
		logex.Debugf("Returned '%s'", returnString)
	}()

	if _, isNoop := s.N.(NodeNoop); isNoop {
		return ""
	}

	out := &bytes.Buffer{}
	// Not sure if we need to capture this exit code for the $? var.
	// Ignore it for now
	_ = s.N.Eval(scp.Copy(), &T.IOContainer{&bytes.Buffer{}, out, os.Stderr})

	return strings.TrimRight(out.String(), "\n")
}
Beispiel #2
0
func (n NodePipe) Eval(scp *variables.Scope, ioc *T.IOContainer) T.ExitStatus {
	lastPipeReader, pipeWriter := io.Pipe()

	scp = scp.Copy()

	cmd := n.Commands[0]
	go cmd.Eval(scp, &T.IOContainer{In: &bytes.Buffer{}, Out: pipeWriter, Err: ioc.Err})

	for _, cmd = range n.Commands[1 : len(n.Commands)-1] {
		pipeReader, pipeWriter := io.Pipe()
		go cmd.Eval(scp, &T.IOContainer{In: lastPipeReader, Out: pipeWriter, Err: ioc.Err})
		lastPipeReader = pipeReader
	}

	cmd = n.Commands[len(n.Commands)-1]
	if !n.Background {
		return cmd.Eval(scp, &T.IOContainer{In: lastPipeReader, Out: ioc.Out, Err: ioc.Err})
	}

	go cmd.Eval(scp, &T.IOContainer{In: lastPipeReader, Out: ioc.Out, Err: ioc.Err})
	return T.ExitSuccess
}