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

unable to use with binary stdout #86

Open
majelbstoat opened this issue Mar 10, 2022 · 2 comments
Open

unable to use with binary stdout #86

majelbstoat opened this issue Mar 10, 2022 · 2 comments

Comments

@majelbstoat
Copy link

I'm using exec.Cmd() to run graphics magick to convert an image, reading from stdin and writing to stdout.

	stdout := bytes.Buffer{}
	stderr := bytes.Buffer{}
	gm := exec.Command("gm", "convert", args...)
	gm.Stdin = bytes.NewReader(img.Data)
	gm.Stdout = &stdout
	gm.Stderr = &stderr

	err = gm.Run()
	if err != nil {
		return nil, fmt.Errorf("gm: %s", stderr.String())
	}
	new := stdout.Bytes()

I've been using go-cmd for all my other commands, but for this use case, it doesn't seem possible, because go-cmd treats all its outputs as strings. Is that correct? I'd love to be doing other work while I wait for the conversion to finish.

@daniel-nichter
Copy link
Member

Yes, it presumes output is lines of strings. Internally, it does just buffer data, but then calls like https://github.com/go-cmd/cmd/blob/v1.4.0/cmd.go#L334 presume string lines. I'm not sure it's feasible to adapt to binary output because the string line presumption is baked into the design.

@majelbstoat
Copy link
Author

Thanks for the clarification. Instead of a replacement, would the addition of a status.StdoutReader which just returned an io.Reader over the internal data, and/or something similar on an OutputStream be feasible, or are there internals that would break if the data was accessed in that way?

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

No branches or pull requests

2 participants