(sigil process)
(sigil process) - Process Management Library
Process management operations including spawning subprocesses, environment variable access, and command execution. Native functions are implemented in C with higher-level utilities defined here.
Running Commands
(import (sigil process))
;; Run and wait for completion
(process-run "ls" "-l")
;; Capture output as string
(process-output->string "date") ; => "Thu Jan 15 14:30:00 2025"
;; Capture output as lines
(process-lines "ls") ; => ("file1" "file2" ...)Spawning Processes
(let ((p (process-spawn "cat")))
(display "Hello\n" (process-stdin p))
(close-output-port (process-stdin p))
(display (read-line (process-stdout p)))
(process-wait p))Environment
(getenv "HOME") ; => "/home/user"
(setenv! "MY_VAR" "value")Exports
process-runprocedureRun a command and wait for it to complete.
Returns the exit status (0 for success).
(process-run "ls" "-l") ; => 0process-spawnprocedureSpawn a subprocess without waiting.
Returns a process object. Use process-wait to wait for completion and retrieve the exit status.
(let ((p (process-spawn "sleep" "10")))
(process-kill! p))process-waitprocedureWait for a process to complete.
Returns the exit status.
(process-wait p) ; => 0process-kill!procedureKill a running process.
(process-kill! p)process?procedureCheck if a value is a process object.
process-alive?procedureCheck if a process is still running.
(process-alive? p) ; => #t or #fprocess-stdinprocedureGet the stdin port of a spawned process.
Returns an output port for writing to the process.
process-stdoutprocedureGet the stdout port of a spawned process.
Returns an input port for reading the process output.
process-stderrprocedureGet the stderr port of a spawned process.
Returns an input port for reading error output.
getenvprocedureGet an environment variable.
Returns the value as a string, or #f if not set.
(getenv "HOME") ; => "/home/user"
(getenv "MISSING") ; => #fsetenv!procedureSet an environment variable.
(setenv! "MY_VAR" "my-value")command-lineprocedureGet the command-line arguments.
Returns a list where the first element is the program name.
(command-line) ; => ("./my-program" "arg1" "arg2")exitprocedureExit the process with a status code.
(exit 0) ; success
(exit 1) ; failureprocess-idprocedureGet the current process ID.
(process-id) ; => 12345command-exists?procedureCheck if a command exists in PATH.
(command-exists? "ls") ; => #t
(command-exists? "foo") ; => #fcall-with-processprocedureCall a procedure with a spawned process.
The process is automatically waited for when proc returns.
(call-with-process "ls" '("-l")
(lambda (p)
(read-line (process-stdout p))))process-output->stringprocedureRun a command and capture its stdout as a string.
Returns #f if the process cannot be started.
(process-output->string "echo" "hello") ; => "hello"
(process-output->string "date") ; => "Thu Jan 15..."read-all-stringprocedureRead all content from a port as a string. Helper for process-output->string.
process-linesprocedureRun a command and return its stdout as a list of lines.
Returns #f if the process cannot be started.
(process-lines "ls") ; => ("file1" "file2" ...)
(process-lines "ls" "-la") ; => ("total 42" "drwxr-x..." ...)read-all-linesprocedureRead all lines from a port. Helper for process-lines.