生成子进程,并获取缓冲输出
Deno Sandboxes provide a sandboxed environment for evaluating JavaScript code. This is useful for evaluating code that is not trusted or for testing code that is not safe to run in the main runtime.
你可以在沙箱中生成子进程,并获取缓冲输出,如下所示。
import { Sandbox } from "@deno/sandbox";
await using sandbox = await Sandbox.create();
const text = await sandbox.sh`pwd`.text();
console.log("result:", text); // → "/home/sandbox\n"
对于长时间运行的进程或大量输出,可以使用 stdout/stderr 流。
For more information about Sandboxes, see the Sandboxes documentation.