Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to v2 module and enable stream redirection #16

Merged
merged 2 commits into from
Sep 14, 2023
Merged

Move to v2 module and enable stream redirection #16

merged 2 commits into from
Sep 14, 2023

Conversation

alexellis
Copy link
Owner

@alexellis alexellis commented Sep 14, 2023

Description

Move to v2 module and enable stream redirection

How Has This Been Tested?

package main

import (
	"bytes"
	"context"
	"fmt"

	gexec "github.com/alexellis/go-execute/v2"
)

func main() {
	buf := bytes.NewBuffer(nil)

	t := gexec.ExecTask{
		Command:            "whoami",
		Shell:              true,
		StreamStdio:        false,
		StdOutWriter:       buf,
		DisableStdioBuffer: true,
	}

	r, err := t.Execute(context.Background())
	if err != nil {
		panic(err)
	}

	if r.ExitCode != 0 {
		panic(r.Stderr)
	}

	fmt.Printf("r.Stdout: %q\n", r.Stdout)
	fmt.Printf("Buffer: %q\n", buf.String())
}

Output:

go run .
r.Stdout: "alex\n"
Buffer: "alex\n"

Also tested with shell enabled/disabled, and with StreamStdio enabled.

Checklist:

I have:

  • updated the documentation and/or roadmap (if required)

* Moves to v2 module style as per google/github-go
* Allows stdio buffer to be disabled for large outputs
* Allows stdio reader/writer replacement fixes: #12

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
@alexellis
Copy link
Owner Author

exec.go Show resolved Hide resolved
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
@michaeladler
Copy link

LGTM

@alexellis alexellis merged commit fc7a3fd into master Sep 14, 2023
@alexellis alexellis deleted the v2 branch September 15, 2023 07:17
alexellis added a commit that referenced this pull request Oct 2, 2023
Previously, DisableStdioBuffer was added in #16, however
was not consumed or used, as reported in #19.

DisableStdioBuffer can now be set, if you only want to stream
directly to stdio, or want to capture the output to your own
writer without buffering.

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow intercepting the stdout/stderr for processing
2 participants