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.

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