For example, suppose I have the following code:
Deno.run({cmd: ['echo', 'hello']})
How do I collect the output of that command which is hello
?
Deno.run
returns an instance of Deno.Process
. Use the method .output()
to get the buffered output.
Don't forget to pass "piped"
to stdout
/stderr
options if you want to read the contents.
const cmd = Deno.run({
cmd: ["echo", "hello"],
stdout: "piped",
stderr: "piped"
});
const output = await cmd.output() // "piped" must be set
cmd.close(); // Don't forget to close it
.output()
returns a Promise
which resolves to a Uint8Array
so if you want the output as a UTF-8 string you need to use TextDecoder
const outStr = new TextDecoder().decode(output); // hello
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With