process Module
The process module enables executing child processes, piping data through standard I/O streams, changing working directories, and inspecting process metadata.
Importing
djazair
use process
Synchronous Execution (process.exec)
Executes a command synchronously and captures its exit code, stdout, and stderr:
djazair
use process
let res = process.exec("git --version")
if res["exit_code"] == 0
print("Git output: ${res["stdout"].strip()}")
else
print("Error: ${res["stderr"]}")
end
Asynchronous Spawning & Pipes
For long-running tasks or streaming stdin/stdout:
djazair
use process
# Spawn process with pipes
let p = process.spawn("sort")
# Write data into child process stdin
process.write(p["write"], "zebra
apple
banana
")
process.close(p["write"]) # Close stdin to signal EOF
# Wait for completion and read sorted stdout
process.wait(p["pid"])
let sortedOutput = process.read(p["read"])
print("Sorted output:
${sortedOutput}")
# apple
# banana
# zebra