@oazmi/kitchensink - v0.10.1
    Preparing search index...

    Function spawnCommand

    • execute an executable process (such as deno, node, winget, apt, curl, cmd, ./bin/main.exe, etc..., but not including shell commands, such as echo, ls, cp, etc...), and then exit it.

      TODO: in the future, add a spawnProcess function which will keep the process alive after executing it, in addition to also permitting it to accept a user's stdin.

      Parameters

      • runtime_enum: RUNTIME

        the runtime enum indicating which runtime should be used for executing/spawning the subprocess.

      • process_name: string

        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).

      • config: Partial<SpawnCommandConfig> = {}

        optional configuration to apply onto the child-process.

      Returns Promise<SpawnCommandResult>

      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