2017-10-01

(sph process create)

create child processes and process chains

subprocess creation with guile

import name

(sph process create)

exports

execute-with-pipes

procedure

signature

proc path arguments #:search-path? [input? output? error?] ->

procedure:{port ... -> any} string list boolean boolean boolean -> any:proc-result integer:exit-status

description

executes a program and calls proc with pipes to or from the standard streams depending on if input/output/error are true.

path is a filesystem path to an executable.

you might have to close ports for proc to return.

pipe ports are closed when after proc returns.

example:

(execute-with-pipes (l (input error) #t) "/usr/bin/echo" (list "test") #t #f #t)

process-chain

procedure

signature

first-input last-output execute-arguments #:search-path? ->

port/any port/any (string/(string:executable string:argument ...) ...) -> (integer:pid ...)

description

creates a new process for each execute-argument and sets standard input and output of the processes in a chaining manner:

input is the first-input or the input from the previous process, the output is the output to the next process or the last-output.

error port for each process is the current-error-port of the process calling process-chain pipes.

if any process could not be created then all previously created processed are sent SIGTERM and the result is an empty list.

tip: if you want to call procedures in between you could start guile processes or use pipe-chain, create the processes yourself and threads for guile code

process-chain->string

procedure

signature

first-input process-chain-arguments ... ->

false/port any ... -> string

process-chain-finish

procedure

signature

process-chain-result ->

false/(integer:pid ...) -> integer

description

wait for the termination of the processes and return the exit status

process-chain-finish-success?

procedure

signature

process-chain-result ->

false/(integer:pid ...) -> boolean

description

wait for the termination of the processes and check if its exit status is 0

process-chain-path-pipe

procedure

signature

first-input last-output config #:search-path? ->

port/string/any port/string/any (#(symbol symbol string/(string:executable string ...)/procedure:{false/string false/string -> string/(string:executable string ...)}) ...) -> (integer:pid ...)

first-input last-output (#(port/path/nothing port/path/nothing path/(path argument ...)/procedure:{path-in path-out -> execute-arguments} ...) ...) -> (integer:pid ...)

description

like process-chain but uses path-pipe-chain internally and so allows automatically created paths (named pipes) between processes.

example:

(path-pipe-process-chain #f (current-output-port)

(list

(vector (q nothing) (q port) (list "echo" "test"))

(vector (q path) (q path) (l (in out) ("program" "--from" in "--to" out)))))

expected result:

assuming that "program" reads from file in and writes to file out, "test" should appear on the current output port

process-create

procedure

signature

executable #:env #:keep-descriptors #:search-path? #:path-open-flags [arguments input-port output-port error-port] ->

string:path/file-name [(string ...) port/string/integer/false ... #:key (env (environ)) (keep-descriptors (list)) search-path? (path-open-flags integer)] -> process-id

description

"executable" is the path or file name of a file to execute to become the new process.

if the given string for "executable" does not start with a slash and search-path? is true (default is false), it is searched in the directories in the PATH environment variable.

the optional parameters are to set the standard streams.

with the key parameters the environment variables for the new process can be set in the format (environ) returns.

no file descriptors from the parent process are transferred to the child except if listed in keep-descriptors or given using the input/output/error-port parameters.

when a string is given as port argument, it is interpreted as a filesystem path and #:path-open-flags can be used to add to O_WRONLY|O_CREAT.

returns the process id of the newly created child process or false if the process could not be created

sph-process-create-description

variable

tags: programming guile documentation library sph-lib q1 process highlight sph-process-create