Exec Module

Run external host commands from JavaScript

Sections

Terminology & Glossary
📖 Documentation
Navigation
31 sectionsv0.1
📄 Exec Module — glaze help exec-module
exec-module

Exec Module

Run external host commands from JavaScript

Topicexecmodulesgojajavascriptgoja-repl

The exec module wraps os/exec so JavaScript runtimes can run external host processes. It is simple by design: one function, command plus arguments, returning the combined standard output and standard error as a string.

JavaScript usage

const exec = require("exec");

const output = exec.run("echo", ["hello", "world"]);
console.log(output);
// "hello world\n"

Module API

run(cmd, args)

Runs cmd with args on the host operating system and returns the combined stdout and stderr as a single string. If the command exits with a non-zero status or cannot be started, the function throws an error.

  • cmd — executable name or absolute path.
  • args — array of string arguments passed to the executable.

Security notes

This module exists to let trusted scripts call local tools, compilers, or system utilities. Because it executes arbitrary host commands, it should only be enabled in runtimes you trust. In untrusted environments, disable the exec module through engine middleware.

Troubleshooting

ProblemCauseSolution
"executable file not found in $PATH" errorThe command name is not on the host PATHUse the absolute path to the executable
Command exits with an errorThe process returned a non-zero exit codeCheck the command arguments and environment before calling
Empty output despite command successThe command wrote everything to stderrRethrow or log errors to see stderr content