testcontainers-go icon indicating copy to clipboard operation
testcontainers-go copied to clipboard

Add function to exec and get output

Open pawalt opened this issue 5 years ago • 13 comments

It would be nice to have a function called ExecOutput that would let the user see the output of an exec command. I've got this fully written with testing; I just want to make sure that this is a welcome addition first :)

pawalt avatar Jan 04 '20 17:01 pawalt

I have it already implemented here: #97

mdelapenya avatar Jan 04 '20 22:01 mdelapenya

Where is it implemented? I don't see anything about execing in a specific container.

pawalt avatar Jan 05 '20 01:01 pawalt

Sorry, typing on mobile... It is a function to retrieve the output of an exec in a container to get the environment variables.

mdelapenya avatar Jan 05 '20 08:01 mdelapenya

Ah I see. I still think that a command that did the exec with the Docker api like the current exec command but also returned the output from the command would be useful as well. The method I have is of the signature:

func (c *DockerContainer) ExecOut(ctx context.Context, cmd []string) (int, string, error) {

pawalt avatar Jan 06 '20 14:01 pawalt

I'd rather using your function, so I'd rebase my PR and use yours instead

mdelapenya avatar Jan 06 '20 18:01 mdelapenya

Awesome. Let me polish it off, and I'll PR.

pawalt avatar Jan 07 '20 15:01 pawalt

Thanks for doing it! Should we use an io.Reader as return type?!

gianarb avatar Jan 08 '20 12:01 gianarb

Yup I'm open to using an io.Reader as the return type. If we're using a reader, do we still want to wait to return until the exec is done, or do we want to allow the user to read off the reader while the command is executing?

pawalt avatar Jan 08 '20 15:01 pawalt

I prefer to have the user reading the io.Reader, it looks more flexible to me

On Wed, Jan 8, 2020 at 4:07 PM Peyton Walters [email protected] wrote:

Yup I'm open to using an io.Reader as the return type. If we're using a reader, do we still want to wait to return until the exec is done, or do we want to allow the user to read off the reader while the command is executing?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/testcontainers/testcontainers-go/issues/126?email_source=notifications&email_token=AAMOAO3TW2HZL7YBBTIAAWTQ4XT4VA5CNFSM4KCXDE42YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEIM3VUI#issuecomment-572111569, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAMOAO77GFYR3ZLKYPCF5MLQ4XT4VANCNFSM4KCXDE4Q .

-- Gianluca Arbezzano www.gianarb.it

gianarb avatar Jan 08 '20 15:01 gianarb

Hey, whats the status of this? Getting the result of the command would be very useful to me, kinda stuck right now with this...

ain-valtin avatar Aug 05 '20 19:08 ain-valtin

This is a legit and Executing a command is what we should implement in Go.

gianarb avatar Sep 21 '20 09:09 gianarb

Hello, Do we have any updates on this? Would like to use this functionality or contribute towards making it work. Thanks!

krisctl avatar Apr 05 '21 17:04 krisctl

This would be very nice

jsirianni avatar Sep 18 '21 02:09 jsirianni

I think we can close this issue, as it was implemented in #435 and released in v0.14.0: it returns the output reader instead of its string representation, so the consumers will handle it in whatever manner they want.

Please consider that it represents a breaking change

Thanks everybody here for your support!

mdelapenya avatar Sep 15 '22 10:09 mdelapenya