Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

The process module

Child processes, and what belongs to the running one, modeled on Rust’s std::process.

process is a module: bring it in with import process (and write process.Command) or import names directly with import [Command, Stream] from process. arguments() and exit() stay in the prelude, and the module passes them on as well.

  • Command: Command describes a program to start; run() waits for it and collects its output, spawn() starts it and returns a Child, and exec() runs it in place of the running program
  • Child: a running child process, its piped streams, and its ExitStatus
  • The running process: id(), executable_path(), and fork(), which starts a copy of it
  • Finding programs: find_executable() looks a program up on the PATH, find_companion() looks beside the running program first, and is_executable() checks a file
  • Signals: signals() returns a channel that receives Ctrl-C, a request to terminate or a hangup, for a clean shutdown

Example

import process;

main(): int {
    var output = process.Command("git").argument("--version").run();
    if (output.is_err()) {
        print("git is not installed");
        return 1;
    }
    print(output.value().stdout);
    return 0;
}

Source: runtime/process/module.pep