// CaptureOutputToFd redirects the current process' stdout and stderr file
// descriptors to the given file descriptor, using the dup2 syscall.
963942
func CaptureOutputToFd(fd int) error {
	err := syscall.Dup2(fd, syscall.Stdout)
	if err != nil {
		return err
	}
	err = syscall.Dup2(fd, syscall.Stderr)
	if err != nil {
		return err
	}
	return nil
}
160647
func ExecOutput(cmdline string) string {
	cmd := startCommand(cmdline)

	var out bytes.Buffer
	cmd.Stdout = &out
	err := cmd.Run()
	if err == nil {
		return out.String()
	}
	return fmt.Sprintf("Error: %s", err.Error())
}
693510
func validateOutputParameter(paramRef string, param *wfv1.Parameter) error {
	if param.ValueFrom == nil {
		return errors.Errorf(errors.CodeBadRequest, "%s.valueFrom not specified", paramRef)
	}
	paramTypes := 0
	for _, value := range []string{param.ValueFrom.Path, param.ValueFrom.JQFilter, param.ValueFrom.JSONPath, param.ValueFrom.Parameter} {
		if value != "" {
			paramTypes++
		}
	}
	switch paramTypes {
	case 0:
		return errors.New(errors.CodeBadRequest, "valueFrom type unspecified. choose one of: path, jqFilter, jsonPath, parameter")
	case 1:
	default:
		return errors.New(errors.CodeBadRequest, "multiple valueFrom types specified. choose one of: path, jqFilter, jsonPath, parameter")
	}
	return nil
}
492179
func muxOutput(streamLabel string, lines chan []byte, clients <-chan net.Conn, targets <-chan io.WriteCloser) {
	var logs []io.WriteCloser
	var conns []io.WriteCloser

	writeAndFilter := func(wc io.WriteCloser, line []byte) bool {
		_, err := wc.Write(line)
		if err != nil {
			wc.Close()
		}
		return err != nil
	}

	logsWriteAndFilter := func(wc io.WriteCloser, line []byte) bool {
		out := []byte(fmt.Sprintf("%s %s %s", time.Now().Format(time.RFC3339Nano), streamLabel, line))
		return writeAndFilter(wc, out)
	}

	for {
		select {
		// an incoming output line to multiplex
		// TODO(lucab): ordered non-blocking writes
		case l := <-lines:
			conns = filterTargets(conns, l, writeAndFilter)
			logs = filterTargets(logs, l, logsWriteAndFilter)

		// a new remote client
		case c := <-clients:
			conns = append(conns, c)

		// a new local log target
		case t := <-targets:
			logs = append(logs, t)
		}
	}
}
1275099
func ioOutputFormatHour(ld *LineData, b *bytes.Buffer) error {
	_, err := b.WriteString(fmt.Sprintf("%02d", ld.TimeStamp.Hour()))
	return err
}
1276965
func NewOutputChannelBuffer(o Output, bufSize int) *OutputChannel {
	oc := &OutputChannel{
		input:  make(chan map[string]interface{}, bufSize),
		output: o,
		stop:   make(chan struct{}),
	}

	go func() {
		for {
			select {
			case msg := <-oc.input:
				if err := o.Write(msg); err != nil {
					critialLogger.Print("cannot write log message: ", err.Error())
				}
			case <-oc.stop:
				close(oc.stop)
				return
			}
		}
	}()

	return oc
}
1160554
func NewErrorOutput(format string, v ...interface{}) OutputModel {
	return OutputModel{
		Error: fmt.Sprintf(format, v...),
	}
}
1206933
func (r *RenderTemplateResult) renderOutput(wr io.Writer) (err error) {
	defer func() {
		if rerr := recover(); rerr != nil {
			resultsLog.Error("ApplyBytes: panic recovery", "recover-error", rerr)
			err = fmt.Errorf("Template Execution Panic in %s:\n%s", r.Template.Name(), rerr)
		}
	}()
	err = r.Template.Render(wr, r.ViewArgs)
	return
}
83253
func (woc *wfOperationCtx) processNodeOutputs(scope *wfScope, prefix string, node *wfv1.NodeStatus) {
	if node.PodIP != "" {
		key := fmt.Sprintf("%s.ip", prefix)
		scope.addParamToScope(key, node.PodIP)
	}
	woc.addOutputsToScope(prefix, node.Outputs, scope)
}
66320
func outputFunc(in worker.Worker, out interface{}) error {
	inWorker, _ := in.(*Tracker)
	if inWorker == nil {
		return errors.Errorf("expected *Tracker input; got %T", in)
	}
	outPointer, _ := out.(*coreleadership.TrackerWorker)
	if outPointer == nil {
		return errors.Errorf("expected *leadership.Tracker output; got %T", out)
	}
	*outPointer = inWorker
	return nil
}
518509
func FlagOutput(in worker.Worker, out interface{}) error {
	inFlag, ok := in.(Flag)
	if !ok {
		return errors.Errorf("expected in to implement Flag; got a %T", in)
	}
	outFlag, ok := out.(*Flag)
	if !ok {
		return errors.Errorf("expected out to be a *Flag; got a %T", out)
	}
	*outFlag = inFlag
	return nil
}
41289
func ioOutputFormatField(field string) func(*LineData, *bytes.Buffer) error {
	return func(ld *LineData, b *bytes.Buffer) error {
		v, exist := ld.Fields[field]
		if !exist {
			return nil
		}
		_, err := b.WriteString(fmt.Sprintf("%v", v))
		return err
	}
}
607072
func (r *REPL) DisableUndefinedOutput(yes bool) *REPL {
	r.undefinedDisabled = yes
	return r
}
477051
func (logger *Logger) AddOutput(uri string, classes ...LogClass) error {
	// generate it
	lo, err := createOutputWrapper(uri, classes)
	if err != nil {
		return err
	}
	if lo == nil {
		return nil
	}

	// Lock our outputs
	logger.outputMutex.Lock()
	defer logger.outputMutex.Unlock()
	logger.outputs = append(logger.outputs, lo)
	return nil
}
1128721
func filesToString(files []*proxy.FileDescriptor) (string, error) {
	out := make([]fileDescriptor, len(files))
	for i, f := range files {
		out[i] = fileDescriptor{
			// Once files will be passed to the child process and their FDs will change.
			// The first three passed files are stdin, stdout and stderr, every next file will have the index + 3
			// That's why we rearrange the FDs for child processes to get the correct file descriptors.
			FileFD:   i + 3,
			FileName: f.File.Name(),
			Address:  f.Address,
		}
	}
	bytes, err := json.Marshal(out)
	if err != nil {
		return "", err
	}
	return string(bytes), nil
}
99455
func OutputWriterFromFile(out *os.File) io.Writer {
	return &ColorWriter{w: out, fd: out.Fd(), mutex: &stdOutMutex, lastFgColor: fgWhite}
}
24965
func (s *JobClient) GetOutput(ctx context.Context, input *GetJobOutputInput) (*GetJobOutputOutput, error) {
	fullPath := path.Join("/", s.client.AccountName, "jobs", input.JobID, "live", "out")

	reqInput := client.RequestInput{
		Method: http.MethodGet,
		Path:   fullPath,
	}
	respBody, respHeader, err := s.client.ExecuteRequestStorage(ctx, reqInput)
	if respBody != nil {
		defer respBody.Close()
	}
	if err != nil {
		return nil, errors.Wrap(err, "unable to get job output")
	}

	output := &GetJobOutputOutput{
		Items: respBody,
	}

	resultSetSize, err := strconv.ParseUint(respHeader.Get("Result-Set-Size"), 10, 64)
	if err == nil {
		output.ResultSetSize = resultSetSize
	}

	return output, nil
}