NAME
std/proc - Process execution, environment, and signals.
SYNOPSIS
from std/proc import Proc, Env, sleep;
let pid := Proc.pid();
let home := Env.get("HOME", "");
let res := Proc.run(
"perl",
[ "-e", "print qq<ok\\n>;" ]
);
let seen := 0;
Proc.onsignal( "USR1", function () {
seen++;
} );
Proc.kill( "USR1", Proc.pid() );
sleep(0.1);
IMPLEMENTATION SUPPORT
This module is supported by zuzu.pl, zuzu-rust, and zuzu-js on Node and Electron. It is not supported by zuzu-js in the browser.
DESCRIPTION
This module provides OS process helpers, environment variable helpers, signal send/receive primitives, process-identification helpers, and process exit.
EXPORTS
Classes
ProcStatic methods:
pid()Parameters: none. Returns:
Number. Returns the current process id.exit(code?)Parameters:
codeis an optional numeric exit status. Returns:null. Exits the current process.run(command, argv?, options?)Parameters:
commandis an executable,argvis an optional array of arguments, andoptionscontrols execution. Returns:Dict. Runs one process and returns its result.Options include
stdin,capture_stdout,capture_stderr, andmerge_stderr. Also supportsenvinjection,cwd, andtimeout.run_async(command, argv?, options?)Parameters: same as
run. Returns:Task. Awaitable version ofrunresolving to the same result dictionary.pipeline(commands, options?)Parameters:
commandsis an array of command specs andoptionscontrols execution. Returns:Dict. Runs commands in sequence, piping captured stdout from each step to the next step's stdin.pipeline_async(commands, options?)Parameters: same as
pipeline. Returns:Task. Awaitable version ofpipelineresolving to the same result dictionary.is_success(result)Parameters:
resultis a process result dictionary. Returns:Boolean. Returns true when the command exited successfully.status_text(result)Parameters:
resultis a process result dictionary. Returns:String. Formats the process status for display.kill(String signal, Number pid?)Parameters:
signalis a signal name andpidis an optional process id. Returns:null. Sends a signal to a process.onsignal(String signal, Function callback)Parameters:
signalis a signal name andcallbackis a handler. Returns:null. Registers a process signal callback.
EnvStatic methods:
get(String name, Any default?)Parameters:
nameis an environment variable name anddefaultis an optional fallback. Returns:Stringor value. Returns an environment variable value or the fallback.set(String name, String value)Parameters:
nameis an environment variable name andvalueis its new value. Returns:null. Sets an environment variable.remove(String name)Parameters:
nameis an environment variable name. Returns:null. Removes an environment variable.
Functions
sleep(seconds)Parameters:
secondsis the delay in seconds. Returns:null. Sleeps for the requested time; fractional seconds are allowed.sleep_async(seconds)Parameters:
secondsis the delay in seconds. Returns:Task. Returns an awaitable task that completes after the requested delay.
COPYRIGHT AND LICENCE
std/proc is copyright Toby Inkster.
It is free software; you may redistribute it and/or modify it under the terms of either the Artistic License 1.0 or the GNU General Public License version 2.