Stream: wasi

Topic: ✔ stdout/stderr component retrieval


view this post on Zulip Rafael Fernández López (Sep 27 2023 at 16:30):

Hello! I am working with wasmtime 13.0.0. I have used the wasi command adapter to migrate a core module to a component, and I'm able to load it using the component loader. However, I'm not able to, using the Rust API, retrieve the stdout from the component. Do you know if there's an example of the sorts? I am able to inherit stdout from the host and let the component print to it, but I'd like to retrieve the result on the rust side. Thanks!

view this post on Zulip Pat Hickey (Sep 27 2023 at 16:36):

wasmtime_wasi::preview2::pipe::MemoryOutputPipe is a trivial implementation for capturing all writes to an output stream to a buffer

view this post on Zulip Pat Hickey (Sep 27 2023 at 16:37):

if you need to consume the stream as the program runs, you can use AsyncWriteStream to wrap your own type that impls AsyncWrite.

view this post on Zulip Pat Hickey (Sep 27 2023 at 16:38):

and you can use things like tokio::io::duplex if you need to redirect that into a buffered channel you can AsyncRead from

view this post on Zulip Rafael Fernández López (Sep 27 2023 at 16:45):

Thanks for the answer! I just figured out that I was using the wrong WasiCtxBuilder when trying this, so it was expecting a dyn WasiFile, instead of the snapshot2 one that expects a impl HostOutputStream :)

view this post on Zulip Notification Bot (Sep 27 2023 at 16:50):

Rafael Fernández López has marked this topic as resolved.


Last updated: Nov 22 2024 at 16:03 UTC