ESC
Type to search...
S
Soli Docs

System Functions

Execute shell commands directly from Soli. Run commands asynchronously with auto-resolving futures or synchronously with blocking calls.

System.run(command)

Runs a command asynchronously and returns a Future that resolves to a Hash containing stdout, stderr, and exit_code.

Parameters

  • command (String) - The command to execute

Returns

Future<Hash> - A future that resolves to:

  • stdout (String) - Standard output
  • stderr (String) - Standard error
  • exit_code (Int) - Exit code (0 for success)

Example

let result = System.run("echo hello")
# result is a Future

# Access properties directly (auto-resolves)
print(result.stdout)   # "hello"
print(result.exit_code) # 0

# Or resolve manually
let output = await(result)
print(output["stdout"])

System.run_sync(command)

Runs a command synchronously (blocking) and returns the result immediately.

Parameters

  • command (String) - The command to execute

Returns

Hash - Contains stdout, stderr, and exit_code.

Example

let result = System.run_sync("ls -la")
print(result["stdout"])
print(result["exit_code"])

Command Substitution

Use backtick syntax for convenient command execution. This is syntactic sugar for System.run().

Example

# Simple command
let result = `echo hello`
print(result.stdout)  # "hello"

# With shell features
let files = `ls *.sl`
print(files.stdout)

# Access exit code
let status = `grep pattern file`
if status.exit_code != 0 {
    println("Pattern not found")
}

Note: Command substitution uses System.run() internally, so it returns a Future that auto-resolves when accessed. This means you can access properties directly without explicitly awaiting.

Shell Features

Commands are parsed to detect shell metacharacters. If detected, the command is executed via sh -c:

  • Pipes: |
  • Redirection: >, <
  • Background: &
  • Sequential: ;
  • Environment: $VAR
  • Subshells: (), ``
  • Quotes: ', "
  • Globbing: *, ?, []
  • Braces: {}, ~

See Also