The simple-inferiors Reference Manual

This is the simple-inferiors Reference Manual, version 1.1.0, generated automatically by Declt version 4.0 beta 2 "William Riker" on Mon Feb 26 17:53:25 2024 GMT+0.

Table of Contents


1 Introduction


2 Systems

The main system appears first, followed by any subsystem dependency.


2.1 simple-inferiors

A very simple library to use inferior processes.

Maintainer

Yukari Hafner <>

Author

Yukari Hafner <>

Home Page

https://Shinmera.github.io/simple-inferiors/

Source Control

(GIT https://github.com/Shinmera/simple-inferiors.git)

Bug Tracker

https://github.com/Shinmera/simple-inferiors/issues

License

zlib

Version

1.1.0

Dependencies
  • uiop (system).
  • bordeaux-threads (system).
  • documentation-utils (system).
Source

simple-inferiors.asd.

Child Components

3 Files

Files are sorted by type and then listed depth-first from the systems components trees.


3.1 Lisp


3.1.1 simple-inferiors/simple-inferiors.asd

Source

simple-inferiors.asd.

Parent Component

simple-inferiors (system).

ASDF Systems

simple-inferiors.


3.1.2 simple-inferiors/package.lisp

Source

simple-inferiors.asd.

Parent Component

simple-inferiors (system).

Packages

simple-inferiors.


3.1.3 simple-inferiors/process.lisp

Dependency

package.lisp (file).

Source

simple-inferiors.asd.

Parent Component

simple-inferiors (system).

Public Interface
Internals

3.1.4 simple-inferiors/documentation.lisp

Dependency

process.lisp (file).

Source

simple-inferiors.asd.

Parent Component

simple-inferiors (system).


4 Packages

Packages are listed by definition order.


4.1 simple-inferiors

Source

package.lisp.

Nickname

org.shirakumo.simple-inferiors

Use List

common-lisp.

Public Interface
Internals

5 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


5.1 Public Interface


5.1.1 Special variables

Special Variable: *cwd*

The variable containing the current directory, virtually.
This variable is only resolved once needed, such as when using WITH-EXCHDIR.

See WITH-CHDIR
See WITH-EXCHDIR

Package

simple-inferiors.

Source

process.lisp.


5.1.2 Macros

Macro: with-chdir ((new-path) &body body)

Changes the directory lazily.
This merges the passed NEW-PATH (resolved through LOCATION) with *CWD* (resolved through LOCATION) and binds that to *CWD*.

See LOCATION
See *CWD*

Package

simple-inferiors.

Source

process.lisp.

Macro: with-exchdir ((&optional new-path) &body body)

Changes the directory directly.
If NEW-PATH is not passed, *CWD* is used instead. Either way it is resolved through LOCATION and checked by CHECK-LOCATION before the actual directory change is performed. This will /also/ act like WITH-CHDIR by additionally rebinding *CWD*.

Note that since a binary can only ever be in one directory at once, you should avoid using this unless necessary, or unless you are sure that the system is not paralellised.

See LOCATION
See CHECK-LOCATION
See *CWD*

Package

simple-inferiors.

Source

process.lisp.


5.1.3 Ordinary functions

Function: copy-stream (input output &key consume-all buffer)

Copies data from INPUT to OUTPUT using the given BUFFER format.
If CONSUME-ALL is non-NIL, all data is read from INPUT until EOF is reached.

BUFFER can be one of
(EQL :LINE) => The stream is copied one line at a time.
(EQL :CAHRACTER) => The stream is copied one character at a time.
INTEGER => A character buffer of size BUFFER is used.

Note that this function tries to be as non-blocking as possible if CONSUME-ALL is NIL. This means that it will only copy anything if there is something to read, but might also read more than one line, character, or buffer at a time, if more data is available.

Once nothing more can be copied, FINISH-OUTPUT on OUTPUT is called.

Package

simple-inferiors.

Source

process.lisp.

Function: ensure-copier (copier-ish)

Ensures that COPIER-ISH is an actual function usable for copying streams.

COPIER-ISH can be one of
FUNCTION => The function is used directly.
INTEGER => MAKE-COPIER is called with the COPIER-ISH.
KEYWORD => MAKE-COPIER is called with the COPIER-ISH.
SYMBOL => The function associated with the symbol is used.

The function must accept an INPUT and OUTPUT stream, as well as in the very least a keyword argument called CONSUME-ALL that, when non-NIL, will copy the whole INPUT to OUTPUT in one go until EOF is reached.

See MAKE-COPIER

Package

simple-inferiors.

Source

process.lisp.

Function: handle-process-parallel (copier process out-in out-out err-in err-out &key stop-attempts stop-sleep)

Handles the PROCESS using COPIER with the OUT-IN, OUT-OUT, ERR-IN, and ERR-OUT streams in parallel. For that, it opens two threads for the respective stream pairs that handle the copying and joins them with the initial thread on unwinding.

As all handlers, this is responsible for copying the data from the IN to the respective OUT streams as well as ensuring that the process is stopped and all remaining data is read on unwinding.

Package

simple-inferiors.

Source

process.lisp.

Function: handle-process-sequential (copier process out-in out-out err-in err-out &key cooldown stop-attempts stop-sleep)

Handles the PROCESS using COPIER with the OUT-IN, OUT-OUT, ERR-IN, and ERR-OUT streams sequentially.
Between copies, it will sleep for COOLDOWN seconds to make sure no excessive CPU is wasted trying to read repeatedly.

As all handlers, this is responsible for copying the data from the IN to the respective OUT streams as well as ensuring that the process is stopped and all remaining data is read on unwinding.

Package

simple-inferiors.

Source

process.lisp.

Function: make-copier (buffer)

Creates a copier function that accepts an input and output stream as well as optional extra arguments using BUFFER. This simply creates a wrapper lambda around COPY-STREAM.

See COPY-STREAM

Package

simple-inferiors.

Source

process.lisp.

Function: run (program args &key input output error on-non-zero-exit handler copier)

Runs an inferior process, supplying PROGRAM with ARGS and using INPUT for STDIN, OUTPUT for STDOUT, and ERROR FOR STDERR.

The current *CWD* is resolved to an actual location, checked for validity, and then used as the location to start the process in. Depending on implementation support, this may have to fall back on using a manual chdir for launching the process.

HANDLER must be a function of six arguments:
COPIER => The function computed by ENSURE-COPIER on COPIER:
PROCESS => The process object used by EXTERNAL-PROGRAM.
OUT-IN => The receiving STDOUT stream from the process.
OUT-OUT => The outputting stream computed by WITH-RESOLVED-STREAM on OUTPUT.
ERR-IN => The receiving STDERR stream from the process.
ERR-OUT => The outputting stream computed by WITH-RESOLVED-STREAM on ERROR.
The handler must ensure that the process is stopped and all data has been copied when an unwind takes place. Furthermore it should not return until the process is done.

ON-NON-ZERO-EXIT can be one of
NIL => NIL is returned.
:RETURN => The exit code is returned.
:ERROR => A INFERIOR-PROCESS-FAILED-ERROR is signalled.
:WARN => A INFERIOR-PROCESS-FAILED-WARNING is signalled.

See *CWD*
See ENSURE-COPIER
See HANDLE-PROCESS-SEQUENTIAL
See HANDLE-PROCESS-PARALLEL

Package

simple-inferiors.

Source

process.lisp.


5.1.4 Generic functions

Generic Reader: failed-args (condition)

Accesses the program arguments passed to RUN that failed to execute properly.

See INFERIOR-PROCESS-FAILED-CONDITION

Package

simple-inferiors.

Methods
Reader Method: failed-args ((condition inferior-process-failed-condition))
Source

process.lisp.

Target Slot

args.

Generic Writer: (setf failed-args) (condition)
Package

simple-inferiors.

Methods
Writer Method: (setf failed-args) ((condition inferior-process-failed-condition))
Source

process.lisp.

Target Slot

args.

Generic Reader: failed-exit (condition)

Accesses the exit code returned from the program that failed to execute properly in RUN.

See INFERIOR-PROCESS-FAILED-CONDITION

Package

simple-inferiors.

Methods
Reader Method: failed-exit ((condition inferior-process-failed-condition))
Source

process.lisp.

Target Slot

exit.

Generic Writer: (setf failed-exit) (condition)
Package

simple-inferiors.

Methods
Writer Method: (setf failed-exit) ((condition inferior-process-failed-condition))
Source

process.lisp.

Target Slot

exit.

Generic Reader: failed-program (condition)

Accesses the program string passed to RUN that failed to execute properly.

See INFERIOR-PROCESS-FAILED-CONDITION

Package

simple-inferiors.

Methods
Reader Method: failed-program ((condition inferior-process-failed-condition))
Source

process.lisp.

Target Slot

program.

Generic Writer: (setf failed-program) (condition)
Package

simple-inferiors.

Methods
Writer Method: (setf failed-program) ((condition inferior-process-failed-condition))
Source

process.lisp.

Target Slot

program.

Generic Function: location (thing)

Attempts to resolve the THING to a pathname.

THING can be one of
NULL => UIOP:GETCWD
PATHNAME => THING
STRING => UIOP:PARSE-NATIVE-NAMESTRING

This generic function is intended to be extended with methods by the user to allow using objects as locations directly.

Package

simple-inferiors.

Source

process.lisp.

Methods
Method: location ((null null))
Method: location ((pathname pathname))
Method: location ((string string))
Reader Method: location ((condition invalid-location-error))
Target Slot

location.

Generic Writer: (setf location) (condition)
Package

simple-inferiors.

Methods
Writer Method: (setf location) ((condition invalid-location-error))
Source

process.lisp.

Target Slot

location.

Generic Function: valid-location-p (thing)

Checks whether THING is a valid (existing) location.

See LOCATION

Package

simple-inferiors.

Source

process.lisp.

Methods
Method: valid-location-p (thing)

5.1.5 Conditions

Condition: inferior-process-failed-error

Error variant of INFERIOR-PROCESS-FAILED-CONDITION

See INFERIOR-PROCESS-FAILED-CONDITION

Package

simple-inferiors.

Source

process.lisp.

Direct superclasses
Condition: inferior-process-failed-warning

Warning variant of INFERIOR-PROCESS-FAILED-CONDITION

See INFERIOR-PROCESS-FAILED-CONDITION

Package

simple-inferiors.

Source

process.lisp.

Direct superclasses
Condition: invalid-location-error

Signalled if an attempt is made to change directory to a location that does not exist.

See LOCATION

Package

simple-inferiors.

Source

process.lisp.

Direct superclasses

error.

Direct methods
Direct slots
Slot: location
Initargs

:location

Readers

location.

Writers

(setf location).


5.2 Internals


5.2.1 Macros

Macro: with-resolved-stream ((stream-ish &key args) &body body)

Resolves the STREAM-ISH to an actual stream and rebinds the symbol.

See CALL-WITH-RESOLVED-STREAM.

Package

simple-inferiors.

Source

process.lisp.


5.2.2 Ordinary functions

Function: %start-process (program args &rest kargs)
Package

simple-inferiors.

Source

process.lisp.

Function: call-with-resolved-stream (func stream-ish &key args)

Resolved STREAM-ISH to an actual stream and calls FUNC with it as its only argument.

STREAM can be one of
NULL => Uses an empty broadcast-stream.
STREAM => Uses the stream directly.
PATHNAME => OPENs the file (passing ARGS) and uses the obtained file-stream. (EQL :STRING) => Uses a string-output-stream.
(EQL T) => Uses *standard-output*

Package

simple-inferiors.

Source

process.lisp.

Function: check-location (thing)

Checks whether THIGN is a valid location and if it isn’t, signals an INVALID-LOCATION-ERROR.

See VALID-LOCATION-P
See INVALID-LOCATION-ERROR

Package

simple-inferiors.

Source

process.lisp.

Function: ensure-process-stopped (process &rest args &key attempts sleep)

Only tries to stop the PROCESS if it is still running.

See STOP-PROCESS

Package

simple-inferiors.

Source

process.lisp.

Function: stop-process (process &key attempts sleep)

Attempt to stop the PROCESS.
It will first try to send a SIGINT every SLEEP seconds for ATTEMPTS times. If the process is still running at that point, a SIGKILL is sent. If the process still won’t quite after a SIGKILL, STOP-PROCESS simply gives up.

Package

simple-inferiors.

Source

process.lisp.


5.2.3 Conditions

Condition: inferior-process-failed-condition

Condition used for when a process returns with a non-zero exit code.

See FAILED-PROGRAM
See FAILED-ARGS
See FAILED-EXIT

Package

simple-inferiors.

Source

process.lisp.

Direct superclasses

condition.

Direct subclasses
Direct methods
Direct slots
Slot: program
Initargs

:program

Readers

failed-program.

Writers

(setf failed-program).

Slot: args
Initargs

:args

Readers

failed-args.

Writers

(setf failed-args).

Slot: exit
Initargs

:exit

Readers

failed-exit.

Writers

(setf failed-exit).


Appendix A Indexes


A.1 Concepts


A.2 Functions

Jump to:   %   (  
C   E   F   G   H   L   M   R   S   V   W  
Index Entry  Section

%
%start-process: Private ordinary functions

(
(setf failed-args): Public generic functions
(setf failed-args): Public generic functions
(setf failed-exit): Public generic functions
(setf failed-exit): Public generic functions
(setf failed-program): Public generic functions
(setf failed-program): Public generic functions
(setf location): Public generic functions
(setf location): Public generic functions

C
call-with-resolved-stream: Private ordinary functions
check-location: Private ordinary functions
copy-stream: Public ordinary functions

E
ensure-copier: Public ordinary functions
ensure-process-stopped: Private ordinary functions

F
failed-args: Public generic functions
failed-args: Public generic functions
failed-exit: Public generic functions
failed-exit: Public generic functions
failed-program: Public generic functions
failed-program: Public generic functions
Function, %start-process: Private ordinary functions
Function, call-with-resolved-stream: Private ordinary functions
Function, check-location: Private ordinary functions
Function, copy-stream: Public ordinary functions
Function, ensure-copier: Public ordinary functions
Function, ensure-process-stopped: Private ordinary functions
Function, handle-process-parallel: Public ordinary functions
Function, handle-process-sequential: Public ordinary functions
Function, make-copier: Public ordinary functions
Function, run: Public ordinary functions
Function, stop-process: Private ordinary functions

G
Generic Function, (setf failed-args): Public generic functions
Generic Function, (setf failed-exit): Public generic functions
Generic Function, (setf failed-program): Public generic functions
Generic Function, (setf location): Public generic functions
Generic Function, failed-args: Public generic functions
Generic Function, failed-exit: Public generic functions
Generic Function, failed-program: Public generic functions
Generic Function, location: Public generic functions
Generic Function, valid-location-p: Public generic functions

H
handle-process-parallel: Public ordinary functions
handle-process-sequential: Public ordinary functions

L
location: Public generic functions
location: Public generic functions
location: Public generic functions
location: Public generic functions
location: Public generic functions

M
Macro, with-chdir: Public macros
Macro, with-exchdir: Public macros
Macro, with-resolved-stream: Private macros
make-copier: Public ordinary functions
Method, (setf failed-args): Public generic functions
Method, (setf failed-exit): Public generic functions
Method, (setf failed-program): Public generic functions
Method, (setf location): Public generic functions
Method, failed-args: Public generic functions
Method, failed-exit: Public generic functions
Method, failed-program: Public generic functions
Method, location: Public generic functions
Method, location: Public generic functions
Method, location: Public generic functions
Method, location: Public generic functions
Method, valid-location-p: Public generic functions

R
run: Public ordinary functions

S
stop-process: Private ordinary functions

V
valid-location-p: Public generic functions
valid-location-p: Public generic functions

W
with-chdir: Public macros
with-exchdir: Public macros
with-resolved-stream: Private macros