Stream: git-wasmtime

Topic: wasmtime / issue #7581 How can I capture stdout and stder...


view this post on Zulip Wasmtime GitHub notifications bot (Nov 24 2023 at 18:50):

skhaz opened issue #7581:

I'd like to know if it's possible to have hooks/handlers for stdout and stderr using Python (or Go, or JavaScript), so that I can execute a .wasm and save the stdout/err in a variable.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 26 2023 at 03:09):

yfaming commented on issue #7581:

WasiConfig in wasmtime-py might be helpful. We can assign a path to stdin_file/stdout_file/stderr_file. It seems we can only redirect stdio into separate file(s).

Here is a simple example:

# pip install wasmtime

from wasmtime import *

def main():
    config = WasiConfig()
    config.stdout_file = "stdout.txt"

    linker = Linker(Engine())
    linker.define_wasi()
    store = Store(linker.engine)
    store.set_wasi(config)

    module = Module.from_file(linker.engine, "wasi_hello.wasm")
    instance = linker.instantiate(store, module)
    instance.exports(store)["_start"](store)

if __name__ == "__main__":
    main()

view this post on Zulip Wasmtime GitHub notifications bot (Nov 26 2023 at 03:12):

skhaz commented on issue #7581:

Thank you so much.

I was using file to do this, I thought that was another way though.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 26 2023 at 03:12):

skhaz closed issue #7581:

I'd like to know if it's possible to have hooks/handlers for stdout and stderr using Python (or Go, or JavaScript), so that I can execute a .wasm and save the stdout/err in a variable.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 26 2023 at 03:51):

yfaming commented on issue #7581:

wasmtime itself (in Rust) supports setting stdin/stdout via WasiCtxBuilder. We can pass any struct implemented WasiFile. Unfortunately, wasmtime-py does not support it ye.


Last updated: Dec 23 2024 at 12:05 UTC