#getting stdout and stderr

1 messages ยท Page 1 of 1 (latest)

trail nexus
#

what are you trying to achieve @next onyx ?

#

There are lots of ways to get the command's stdout and stderr, just not specifically in that exact way

#

How important is it that it specifically goes through dagger's stdout and stderr?

next onyx
#

I want (sort of need) to get stdout and stderr from a command run inside of dagger out to stdout and stderr outside of dagger.

#

I guess I could write it to a file inside the container and then use the files, but seems like a weird coupling.

#

since some of the ways I am thinking of using this involve pipes

buoyant maple
trail nexus
#

Yeah at the moment the Dagger API doesn't expose the client's stdout & stderr, but it's an interesting idea

next onyx
#

stderr can be written to w/o an error exitcode

trail nexus
#

Often when one runs into this kind of problem ("how to compose a call to dagger with other tools outside dagger?") the solution ends up being "just wrap the other tool in dagger too" ๐Ÿ™‚

next onyx
#

@trail nexus I'm not sure if it's a good idea or not, but ... at least thinking with my go api hat on ... a function that returns (string,string) or (string,string,error) could map the first string to stdout and the second to stderr

#

I want to call said function from vscode. I don't want to wrap vscode in dagger.

trail nexus
#

mmm, but if your dagger call ends with a with-exec wouldn't that just go to stdout/stderr automatically?

next onyx
#

does it ?

trail nexus
#

ie. dagger call container from --address=alpine with-exec sh,-c,"echo foo; echo >&2 bar"

next onyx
#

well you are squashing stdout/stderr together there

buoyant maple
#

&2 combines them to one

next onyx
#

well actually no .. sorry I hate the redirect syntax

#

or maybe. dammit decades of using these and I still can't remember the exact right syntax. ๐Ÿ™‚

#

&2 redirect 1 to 2 ... but that was the point. ๐Ÿ™‚

buoyant maple
#

dont think i can help here much, i think your wizardry is beyond my own level

next onyx
#

BTW

$ dagger core -s container from --address=alpine with-exec --args sh,-c,"echo foo; echo >&2 bar"
_type: Container
defaultArgs:
    - /bin/sh
entrypoint: []
mounts: []
platform: linux/arm64
user: ""
workdir: /
#

so no I guess not?

buoyant maple
#

with-exec returns you the ctr which that cmd which executed, i guess.. you want stdout after that, since its been 'redirected?'

next onyx
#

but...

$ dagger core -s container from --address=alpine with-exec --args sh,-c,"echo foo; echo >&2 bar" stdout
foo
dagger core -s container from --address=alpine with-exec --args sh,-c,"echo foo; echo >&2 bar" stderr
bar
#

@trail nexus ^

#

@buoyant maple So yes, maybe I do want a stdouterr as per your earlier suggestion. As long as it maps correctly.

trail nexus
#

right the point is to test what happens when you select neither stdout nor stderr

next onyx
#

@trail nexus read up

trail nexus
#

I guess sync or exit-code to force execution

next onyx
#

adding sync just returns a base64 encoded hash

trail nexus
#

damnit

next onyx
#

adding exit-code returns 0

trail nexus
#

right. but the TUI outputs stuff to stderr

#

which is what I was hoping we could take advantage of

next onyx
#

it doesn't in these cases everything goes to stdout

trail nexus
#

๐Ÿค”๐Ÿค”๐Ÿค” @vernal pagoda is there a magical tui flag that allows a withExec to take over the client's stdout/stderr, so that dagger call can act as a shim to the containerized tool?

#

ie. so that dagger call ... with-exec foo feels the same as foo from the caller's point if view?

#

like a "pass through mode"

next onyx
#

a stdouterr command that did this by default would be ++ IMO.

trail nexus
#

that command would be very useful also but won't do what you want, it will produce a string with the mixed streams

next onyx
#

well the tui could do the needful maybe?

trail nexus
#

this is more like a flag for the entire session OR maybe for withExec

#

the thing about configuring it session-wide (like a flag to the dagger CLI) is that it would have to apply to all withExecs in the session which may not be what you want

next onyx
#

yeah, it's probably not .. at least I can imagine reasons/times when you don't

#

if a function returns an error does the error text go to stderr or stdout ?

trail nexus
#

stderr

next onyx
#

hmm. well returning stderr as an error doesn't help exactly since it causes the command to actually error too.

#

I can probably do this with some additional scripting, but it would be nice if there was a nice friendly way to do this...

From the Go SDK perspective I still like the idea of (string, string, error) or (string,string) returns meaning (stdout, stderr, ...)

#

But I have no idea what sort of shenanigans would be required to make that work or what issues it would cause.

trail nexus
#

Do you actually need stderr if there is no error? presumably errors are when vscode actually needs to show you stderr in most cases

trail nexus
next onyx
#

a tuple is a single composite value?