Skip to content

Spawn

Use JSTime.spawn() to spawn a child process.

const proc = JSTime.spawn(["echo", "hello"]);
// await completion
await proc.exited;

The second argument accepts a configuration object.

const proc = JSTime.spawn("echo", ["Hello, world!"], {
cwd: "/tmp",
env: { FOO: "bar" },
onExit(proc, exitCode, signalCode, error) {
// exit handler
},
});

By default, the stdout of the child process can be consumed as a ReadableStream using proc.stdout.

const proc = JSTime.spawn(["echo", "hello"]);
const output = await new Response(proc.stdout).text();
output; // => "hello"

See Docs > API > Child processes for complete documentation.