Process type

Running or finished process

Methods

$()(p:Process) Source: stdlib.ngs:7316
Run a process
$()(p:Process) Source: stdlib.ngs:7438
Mock external processes - record
=~(x:Process, cp:CommandsPipeline, mc:MatchContext) Source: stdlib.ngs:7696
Match process based on argv and options
ExitCode(p:Process) Source: stdlib.ngs:7170
Convert Process to exit code. Waits for the process to finish and uses its exit code. To be used for NGS process exit such as in "ngs -e 'my_code(); $(ls)'".
finished(p:Process) Source: stdlib.ngs:7045
Check whether the process has exited, without waiting. Records exit_code and exit_signal when it has. While another thread's wait() is in progress, returns false until that wait() records the exit.

Returns

Bool

Example

p = $(sleep 1 &).processes[0]
finished(p)  # false
$(sleep 2)
finished(p)  # true
finished_ok(p:Process) Source: stdlib.ngs:6879
Decide whether process finished normally: exit code must be 0. Note that processes terminated by a signal will have .exit_code null.

Parameters

pany process

Returns

bool
finished_ok(p:Process, field_name:Str, ok:NumRange)internal Source: stdlib.ngs:6886
Decide whether a process finished normally.

Example

$(ok:0..10 ls no-such-file)
finished_ok(p:Process, field_name:Str, ok:Arr)internal Source: stdlib.ngs:6892
Decide whether a process finished normally.

Example

$(ok:[0,1,2] ls no-such-file)
finished_ok(p:Process, field_name:Str, ok:Int)internal Source: stdlib.ngs:6900
Decide whether a process finished normally.

Example

$(ok:1 ls no-such-file)  # No exception
$(ok:10 ls no-such-file) # ProcessFail exception
finished_ok(p:Process, field_name:Str, ok:Bool)internal Source: stdlib.ngs:6906
Decide whether a process finished normally.

Example

# 'ok' option is set to true when the value is missing after ':'
$(ok: ls no-such-file)
finished_ok(p:Process)internal Source: stdlib.ngs:6916
Decide whether a process with 'ok' option finished normally.

Example

$(ok:0..10 ls no-such-file)
$(ok:[0,1,2] ls no-such-file)
$(ok:1 ls no-such-file)  # No exception
$(ok:10 ls no-such-file) # ProcessFail exception
$(ok: ls no-such-file)
finished_ok(p:Process) Source: stdlib.ngs:6932
Decide whether a process with 'ok_sig' option, terminated by a signal, finished normally. A process with 'ok_sig' option that exited normally is checked as usual, by its exit code.

Example

p=$(sleep 10 &); p.kill(); p.wait()  # ProcessFail exception in wait()
p=$(ok_sig:SIGNALS.TERM sleep 10 &); p.kill(); p.wait()  # No exception
finished_ok(p:Process) Source: stdlib.ngs:6951
Decide whether a process finished normally for known programs that return also non-zero exit codes which do not signal a failure.

Example

$(test -f my_file_that_might_be_present)
$(fuser my_file)  # On Linux, exit code 1 means file is not used
init(p:Process, c:Command) Source: stdlib.ngs:6976
Process constructor. Initializes fields.
init(pf:ProcessFail, process:Process) Source: autoload/globals/ProcessFail.ngs:4
Undocumented
kill(p:Process, sig:Int=15) Source: stdlib.ngs:7128
Send signal to a Process. Uses KILL(2). Throws InvalidArgument if Process does not have "pid". Throws KillFail on error. Sends nothing if the process has exited: its pid may already belong to another process. While another thread's wait() is in progress, signals the process even if it has exited (its pid is not reused until that wait() reaps it).

Parameters

sigSignal to send. Defaults to SIGNALS.TERM

Returns

unspecified at this time, do not count on it
lines(p:Process) Source: stdlib.ngs:7789
Wait for the process and return lines of its stdout.

Returns

Arr of Str

Example

$(seq 10 2 20).lines().map(Int)  # [10,12,14,16,18,20]
lines(p:Process, cb:Fun) Source: stdlib.ngs:7795
Iterate lines of Process' stdout, calling cb with successive lines. Warning: current implementation waits for the process to finish, accumulates all its stdout, and only then starts calling cb for each line.
Str(p:Process) Source: stdlib.ngs:7189
Wait for the process to finish and return its standard output.

Returns

Str
wait(p:Process) Source: stdlib.ngs:7061
Wait for a process. Waits for reading and writing threads to finish. Waits for the process to finish. Checks whether to throw ProcessFail using finished_ok(), on every call.

Returns

p