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.
yfaming commented on issue #7581:
WasiConfig
in wasmtime-py might be helpful. We can assign a path tostdin_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()
skhaz commented on issue #7581:
Thank you so much.
I was using file to do this, I thought that was another way though.
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.
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: Nov 22 2024 at 17:03 UTC