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

    Function execShellCommand

    • execute a shell/terminal command on system runtimes (i.e. RUNTIME.DENO, RUNTIME.BUN, or RUNTIME.NODE). otherwise an error gets thrown on all other environments, since they do not support shell command execution.

      Note

      we don't use Deno.Command for deno here, because it does not default to your os's native preferred terminal, and instead you will need to provide one yourself (such as "bash", "cmd", "shell", etc...). which is why we use node:child_process for all three runtimes.

      Parameters

      • runtime_enum: RUNTIME

        the runtime enum indicating which runtime should be used for querying the environment variable.

      • command: string

        the shell command to execute.

      • config: Partial<ExecShellCommandConfig> = {}

        optional configuration to apply onto the shell child-process.

      Returns Promise<ExecShellCommandResult>

      a promise that is resolved when the child process that executed the command has closed.

      import { assertEquals, assertStringIncludes } from "jsr:@std/assert"

      {
      const { stdout, stderr } = await execShellCommand(identifyCurrentRuntime(), "echo Hello World!")
      assertStringIncludes(stdout, "Hello World!")
      assertEquals(stderr, "")
      }

      {
      const { stdout, stderr } = await execShellCommand(identifyCurrentRuntime(), "echo", { args: ["Hello", "World!"] })
      assertStringIncludes(stdout, "Hello World!")
      assertEquals(stderr, "")
      }