IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: 1.0.0b1
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

run

run(cmd: String) -> String

Runs the specified command and returns the output as a string.

This function executes the given command in a subprocess, captures its standard output, and returns it as a string. It automatically handles opening and closing the subprocess.

Args:

  • cmd (String): The command to execute as a string.

Returns:

String: The standard output of the command as a string, with trailing whitespace removed.

Raises:

This function raises if:

  • The command cannot be executed.
  • There is an IO error reading from the subprocess.
  • The data written by the subprocess is not valid UTF-8.