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:
Commanddescribes a program to start;run()waits for it and collects its output,spawn()starts it and returns aChild, andexec()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(), andfork(), which starts a copy of it - Finding programs:
find_executable()looks a program up on thePATH,find_companion()looks beside the running program first, andis_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