#getting stdout and stderr
1 messages ยท Page 1 of 1 (latest)
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?
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
I was checking the cookbooks, i was sure I saw something about getting stderror or handling a failed cmd and continuing: https://docs.dagger.io/cookbook#continue-using-a-container-after-command-execution-fails But i dont think this really is what youre after.
Yeah at the moment the Dagger API doesn't expose the client's stdout & stderr, but it's an interesting idea
stderr can be written to w/o an error exitcode
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" ๐
@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.
mmm, but if your dagger call ends with a with-exec wouldn't that just go to stdout/stderr automatically?
does it ?
ie. dagger call container from --address=alpine with-exec sh,-c,"echo foo; echo >&2 bar"
well you are squashing stdout/stderr together there
&2 combines them to one
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. ๐
dont think i can help here much, i think your wizardry is beyond my own level
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?
with-exec returns you the ctr which that cmd which executed, i guess.. you want stdout after that, since its been 'redirected?'
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.
right the point is to test what happens when you select neither stdout nor stderr
I guess sync or exit-code to force execution
adding sync just returns a base64 encoded hash
damnit
adding exit-code returns 0
right. but the TUI outputs stuff to stderr
which is what I was hoping we could take advantage of
it doesn't in these cases everything goes to stdout
๐ค๐ค๐ค @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"
a stdouterr command that did this by default would be ++ IMO.
that command would be very useful also but won't do what you want, it will produce a string with the mixed streams
well the tui could do the needful maybe?
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
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 ?
stderr
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.
Do you actually need stderr if there is no error? presumably errors are when vscode actually needs to show you stderr in most cases
Graphql does not support multiple return values so that is not possible
a tuple is a single composite value?