osproc
nimony/lib/std/osproc.nim
The std/osproc module implements an advanced facility for executing OS processes and process communication.
This is the Nimony port. Compared to the upstream Nim module the POSIX path uses fork + execve exclusively (no posix_spawn — its attribute types are opaque libc-internal structs, which std/posix no longer binds) and the timeout path of waitForExit uses a busy-wait with nanosleep.
See also:
type FileHandle = int32OS-level file descriptor.
type ProcessOption = enum poEchoCmd = (0, "poEchoCmd") poUsePath = (1, "poUsePath") poEvalCommand = (2, "poEvalCommand") poStdErrToStdOut = (3, "poStdErrToStdOut") poParentStreams = (4, "poParentStreams") poInteractive = (5, "poInteractive") poDaemon = (6, "poDaemon")
func dollar`.ProcessOption(e: ProcessOption): stringtype Process = ref ProcessObjRepresents an operating system process.
proc processID(p: ref ProcessObj): int64Returns
p's process ID.proc inputHandle(p: ref ProcessObj): int32Returns
p's input file handle for writing to.proc outputHandle(p: ref ProcessObj): int32Returns
p's output file handle for reading from.proc errorHandle(p: ref ProcessObj): int32Returns
p's error file handle for reading from.proc startProcess(command: string; workingDir: string; args: openArray; env: ref StringTableObj; options: set[ProcessOption]): ref ProcessObjproc close(p: ref ProcessObj)proc suspend(p: ref ProcessObj)proc resume(p: ref ProcessObj)proc terminate(p: ref ProcessObj)proc kill(p: ref ProcessObj)proc running(p: ref ProcessObj): boolproc waitForExit(p: ref ProcessObj; timeout: int64): int64proc peekExitCode(p: ref ProcessObj): int64proc inputStream(p: ref ProcessObj): ref StreamObjproc outputStream(p: ref ProcessObj): ref StreamObjproc errorStream(p: ref ProcessObj): ref StreamObjproc execCmd(command: string): int64Executes
commandand returns its error code.iterator lines(p: ref ProcessObj; keepNewLines: bool): stringIterates line-by-line over the process's stdout until EOF, then waits for the process to exit.
proc readLines(p: ref ProcessObj): tuple[seq, int64]Reads all stdout lines and returns them together with the exit code.
proc execProcess(command: string; workingDir: string; args: openArray; env: ref StringTableObj; options: set[ProcessOption]): stringExecutes
commandand returns its combined stdout as a string.proc execCmdEx(command: string; options: set[ProcessOption]; env: ref StringTableObj; workingDir: string; input: string): tuple[string, int64]Runs
command, returning its output and exit code.proc execProcesses(cmds: openArray; options: set[ProcessOption]; n: int64): int64Executes
cmdswith at mostnin flight concurrently. Returns the maximum absolute exit code.beforeRunEvent/afterRunEventhooks are omitted here; subscribe to them upstream if you need the callbacks.