the runtime enum indicating which runtime should be used for executing/spawning the subprocess.
the name of the process to spawn.
this could be either something in your environment's PATH variable,
or an executable in your current directory (which will require you to prepend a leading "./" or "../" in its path).
optional configuration to apply onto the child-process.
a promise that is resolved when the spawned child process exits that executed the command has closed.
import { assertEquals, assertStringIncludes } from "jsr:@std/assert"
const toText = (bytes: Uint8Array) => (new TextDecoder().decode(bytes))
const runTestWithRuntime = async (runtime_enum: RUNTIME) => {
{
const { stdout, stderr } = await spawnCommand(runtime_enum, "deno", {
args: ["eval", `console.log("child-process says hello!")`],
})
assertStringIncludes(toText(stdout), "child-process says hello!")
assertEquals(toText(stderr), "")
}
if (Deno.build.os === "windows") {
const { stdout, stderr } = await spawnCommand(runtime_enum, "ipconfig")
assertStringIncludes(toText(stdout).toLowerCase(), "windows ip configuration")
assertEquals(toText(stderr), "")
}
if (Deno.build.os === "linux" || Deno.build.os === "darwin") {
// `echo` is apparently a process, and not a shell utility. (insert surprised pikachu face)
const { stdout, stderr } = await spawnCommand(runtime_enum, "echo", { args: ["Hello", "World!"] })
assertStringIncludes(toText(stdout), "Hello World!")
assertEquals(toText(stderr), "")
}
}
await runTestWithRuntime(identifyCurrentRuntime()) // deno runtime test
await runTestWithRuntime(RUNTIME.NODE) // deno with node-compatibility runtime test
execute an executable process (such as
deno,node,winget,apt,curl,cmd,./bin/main.exe, etc..., but not including shell commands, such asecho,ls,cp, etc...), and then exit it.TODO: in the future, add a
spawnProcessfunction which will keep the process alive after executing it, in addition to also permitting it to accept a user'sstdin.