MangoPeachGrape opened issue #11963:
Hi,
I would like to have a way to redirect stdout/stderr to an in-memory queue or pipe, and then have some API to get the output from C.
I see
MemoryOutputPipeinp2/pipe.rs, but I'm unsure if calling.contents()removes from the underlying pipe? I think I would prefer if a reading operation would remove from it, so that the pipe wouldn't get full.I was also thinking, what would be the API for this? Would reading from the pipe require an allocation and a copy, or could we get away with passing an non-owning pointer to the data to some callback instead?
Feel free to let me know if any ideas come to mind!
Thanks,
MangoPeachGrape
alexcrichton commented on issue #11963:
Would something like this work?
typedef size_t (*wasi_output_callback_t)(void *, const void *, size_t); WASI_API_EXTERN bool wasi_config_set_stdout_custom(wasi_config_t *config, wasi_output_callback_t callback, void *env, void (*finalizer)(void *));Basically the ability to have a custom callback which receives the bytes and can figure out what to do with it. That'd be up to the C implementation to figure out how to collect the output but being able to customize it entirely is sort of the next level up from what we currently have in the API.
(something similar could in theory be used for stdin too)
MangoPeachGrape commented on issue #11963:
I think so yes!
I was thinking of it requiring a variant of
MemoryOutputPipewith a callback to its data, but your solution seems _a lot_ better.Should I try implementing it?
alexcrichton commented on issue #11963:
Please do!
alexcrichton added the wasmtime:c-api label to Issue #11963.
alexcrichton closed issue #11963:
Hi,
I would like to have a way to redirect stdout/stderr to an in-memory queue or pipe, and then have some API to get the output from C.
I see
MemoryOutputPipeinp2/pipe.rs, but I'm unsure if calling.contents()removes from the underlying pipe? I think I would prefer if a reading operation would remove from it, so that the pipe wouldn't get full.I was also thinking, what would be the API for this? Would reading from the pipe require an allocation and a copy, or could we get away with passing an non-owning pointer to the data to some callback instead?
Feel free to let me know if any ideas come to mind!
Thanks,
MangoPeachGrape
Last updated: Dec 06 2025 at 06:05 UTC