the runtime enum indicating which runtime should be used for executing the shell command.
the shell command to execute.
optional configuration to apply onto the shell child-process.
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, "")
}
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.
we don't use
Deno.Commandfor 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 usenode:child_processfor all three runtimes.TODO: add support for txiki.js. this is non-trivial, because, just like
Deno.command, thetjs.spawnfunction 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 sendingstdin, while also capturingstdoutwithout the echoedstdin.TODO: add support for adding custom env-variables to the child shell process.