Link Search Menu Expand Document

Process

Table of contents

  1. Process
    1. Process.exec(List) -> Result<Nil>
    2. Process.run(List, Boolean: captureOutput -> Optional) -> Result<Nil>

Process

To make use of the Process module an import is required.

import Process;

Process.exec(List) -> Result<Nil>

Executing an external process can be done via .exec. Unlike .run() exec does not wait for the process to finish executing, so it is only useful for circumstances where you wish to “fire and forget”.

.exec() expects a list as a parameter which is the command and any arguments for the command as individual list elements, which all must be strings. It will return a Result that unwraps to nil on success.

Process.exec(["ls", "-la"]);

Process.run(List, Boolean: captureOutput -> Optional) -> Result<Nil>

Similar to .exec() except this will wait for the external process to finish executing.

.run() expects a list as a parameter which is the command and any arguments for the command as individual list elements, and it will return a Result that unwraps to nil on success.

If the external process writes to stdout and you wish to capture the output you can pass an optional boolean argument to .run(), this will instead make the Result unwrap to a string of the captured output.

Process.run(["ls", "-la"]).unwrap();
print(Process.run(["echo", "test"], true).unwrap()); // 'test'

This site uses Just The Docs, with modifications.