// GetOutputs is a helper method that returns both stdout and stderr outputs
// from the runner.
15690
func GetOutputs(r Runner) (io.Reader, io.Reader, error) {
	stdout, err := r.StdoutPipe()
	if err != nil {
		return nil, nil, err
	}

	stderr, err := r.StderrPipe()
	if err != nil {
		return nil, nil, err
	}

	return bufio.NewReader(stdout), bufio.NewReader(stderr), nil
}
970870
func (w *Wallet) UnspentOutputs(policy OutputSelectionPolicy) ([]*TransactionOutput, error) {
	var outputResults []*TransactionOutput
	err := walletdb.View(w.db, func(tx walletdb.ReadTx) error {
		addrmgrNs := tx.ReadBucket(waddrmgrNamespaceKey)
		txmgrNs := tx.ReadBucket(wtxmgrNamespaceKey)

		syncBlock := w.Manager.SyncedTo()

		// TODO: actually stream outputs from the db instead of fetching
		// all of them at once.
		outputs, err := w.TxStore.UnspentOutputs(txmgrNs)
		if err != nil {
			return err
		}

		for _, output := range outputs {
			// Ignore outputs that haven't reached the required
			// number of confirmations.
			if !policy.meetsRequiredConfs(output.Height, syncBlock.Height) {
				continue
			}

			// Ignore outputs that are not controlled by the account.
			_, addrs, _, err := txscript.ExtractPkScriptAddrs(output.PkScript,
				w.chainParams)
			if err != nil || len(addrs) == 0 {
				// Cannot determine which account this belongs
				// to without a valid address.  TODO: Fix this
				// by saving outputs per account, or accounts
				// per output.
				continue
			}
			_, outputAcct, err := w.Manager.AddrAccount(addrmgrNs, addrs[0])
			if err != nil {
				return err
			}
			if outputAcct != policy.Account {
				continue
			}

			// Stakebase isn't exposed by wtxmgr so those will be
			// OutputKindNormal for now.
			outputSource := OutputKindNormal
			if output.FromCoinBase {
				outputSource = OutputKindCoinbase
			}

			result := &TransactionOutput{
				OutPoint: output.OutPoint,
				Output: wire.TxOut{
					Value:    int64(output.Amount),
					PkScript: output.PkScript,
				},
				OutputKind:      outputSource,
				ContainingBlock: BlockIdentity(output.Block),
				ReceiveTime:     output.Received,
			}
			outputResults = append(outputResults, result)
		}

		return nil
	})
	return outputResults, err
}
182866
func RunOutputDirPath(dirPath string, args ...string) ([]byte, error) {
	stdout := bytes.NewBuffer(nil)
	err := RunIODirPath(IO{Stdout: stdout}, dirPath, args...)
	return stdout.Bytes(), err
}
344809
func (logger *Logger) Output(calldepth int, s string) error {
	_, err := logger.Write([]byte(s))

	return err
}
304943
func Output(cmd string, args ...string) (string, error) {
	buf := &bytes.Buffer{}
	_, err := Exec(nil, buf, os.Stderr, cmd, args...)
	return strings.TrimSuffix(buf.String(), "\n"), err
}
1191977
func (a *application) getOutputFactory() (outputFactory, error) {
	factory := a.outputConfig.getFactory()
	if factory == nil {
		return nil, errors.New("main: No output is configured")
	}
	return factory, nil
}
1350925
func (s *Job) SetOutputs(v []*JobOutput) *Job {
	s.Outputs = v
	return s
}
943128
func FullOutput(c *exec.Cmd) (stdout []byte, stderr []byte, code int, err error) {
	var outbuf, errbuf bytes.Buffer

	c.Stdout = &outbuf
	c.Stderr = &errbuf

	if runtime.GOOS == "windows" {
		// For powershell, if running a script we need to execute it with a -File option
		// otherwise the return code will get lost
		if len(c.Args) == 2 && strings.Contains(c.Args[0], "powershell.exe") && strings.HasSuffix(c.Args[1], ".ps1") {
			c.Args = []string{c.Args[0], "-File", c.Args[1]}
		}
	}
	if err := c.Start(); err != nil {
		return nil, nil, 0, err
	}

	err = c.Wait()
	code, err = exitCode(err)
	stdout = outbuf.Bytes()
	stderr = errbuf.Bytes()

	return stdout, stderr, code, err
}
1307395
func (p *Printer) AddOutput(writers ...io.Writer) *Printer {
	p.mu.Lock()
	defer p.mu.Unlock()

	for _, w := range writers {
		// set is terminal to false
		// if at least one of the writers
		// is not a terminal-based.
		if !terminal.IsTerminal(w) {
			p.IsTerminal = false
			break
		}
	}

	w := io.MultiWriter(append(writers, p.Output)...)
	p.Output = w
	return p

	// p.mu.Lock()
	// oldW := p.Output
	// newW := io.MultiWriter(writers...)
	// p.Output = writerFunc(func(p []byte) (n int, err error) {
	// 	n, err = oldW.Write(p)
	// 	if err != nil {
	// 		return
	// 	}
	// 	if n != len(p) {
	// 		err = io.ErrShortWrite
	// 		return
	// 	}
	// 	return newW.Write(p)
	// })
	// p.mu.Unlock()
}
640794
func (s *SqlApplicationConfiguration) SetOutputs(v []*Output) *SqlApplicationConfiguration {
	s.Outputs = v
	return s
}
1184790
func getOutputSerializationOpts(ctx *cli.Context, csvHdrs []string) (opts map[string]map[string]string) {
	m := make(map[string]map[string]string)

	ocsv := ctx.String("csv-output")
	ojson := ctx.String("json-output")
	csvType := ctx.IsSet("csv-output")
	jsonType := ctx.IsSet("json-output")

	if csvType && jsonType {
		fatalIf(errInvalidArgument(), "Only one of --csv-output, or --json-output can be specified as output serialization option")
	}

	if jsonType && len(csvHdrs) > 0 {
		fatalIf(errInvalidArgument(), "--csv-output-header incompatible with --json-output option")
	}

	if csvType {
		validKeys := append(validCSVCommonKeys, validJSONCSVCommonOutputKeys...)
		kv, err := parseSerializationOpts(ocsv, append(validKeys, validCSVOutputKeys...), validCSVOutputAbbrKeys)
		fatalIf(err, "Invalid value(s) specified for --csv-output flag")
		m["csv"] = kv
	}

	if jsonType {
		kv, err := parseSerializationOpts(ojson, validJSONCSVCommonOutputKeys, validJSONOutputAbbrKeys)
		fatalIf(err, "Invalid value(s) specified for --json-output flag")
		m["json"] = kv
	}
	return m
}
513347
func (s *AddFlowOutputsOutput) SetOutputs(v []*Output) *AddFlowOutputsOutput {
	s.Outputs = v
	return s
}
821343
func formatOutput(data interface{}, format string) ([]byte, error) {
	var out string

	switch format {

	case "json":
		jsonout, err := json.MarshalIndent(data, "", "  ")
		if err != nil {
			return nil, err
		}
		out = string(jsonout)

	case "text":
		out = data.(fmt.Stringer).String()

	default:
		return nil, fmt.Errorf("Invalid output format \"%s\"", format)

	}
	return []byte(prepareOutput(out)), nil
}
509397
func consoleOutput(call otto.FunctionCall) otto.Value {
	output := []string{"JS:> "}
	for _, argument := range call.ArgumentList {
		output = append(output, fmt.Sprintf("%v", argument))
	}
	fmt.Fprintln(os.Stderr, strings.Join(output, " "))
	return otto.Value{}
}
173825
func (r Result) CombinedOutput() string {
	strs := []string{}
	if sout := r.Stdout.String(); sout != "" {
		strs = append(strs, fmt.Sprintf("[stdout]: %s", sout))
	}
	if serr := r.Stderr.String(); serr != "" {
		strs = append(strs, fmt.Sprintf("[stderr]: %s", serr))
	}
	return strings.Join(strs, ", ")
}
1494
func (s *AutomationExecution) SetOutputs(v map[string][]*string) *AutomationExecution {
	s.Outputs = v
	return s
}
107819
func getOutput(filename string) (*os.File, error) {
	if filename == "-" || filename == "" {
		return os.Stdout, nil
	}

	return os.Create(filename)
}