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

    Function execShellCommand

    • execute a shell/terminal command on system runtimes (i.e. RUNTIME.DENO, RUNTIME.BUN, or RUNTIME.NODE, RUNTIME.TXIKI). 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.

      TODO: add support for txiki.js. this is non-trivial, because, just like Deno.command, the tjs.spawn function only spawns processes, and not your default terminal. but that's not the only issue; spawning a terminal on txiki.js also hasn't quite worked consistiently for me. the problem lies in sending stdin, while also capturing stdout without the echoed stdin.

      TODO: add support for adding custom env-variables to the child shell process.

      Parameters

      • runtime_enum: RUNTIME

        the runtime enum indicating which runtime should be used for executing the shell command.

      • 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, "")
      }