child_process/stdio
Types
Values
pub fn capture_stderr(stdio: Stdio) -> Stdio
Capture stderr in addition to stdout for streaming configurations.
Only applies to stream and lines configurations.
Example
stdio.lines(fn(line) { io.print(line) })
|> stdio.capture_stderr()
pub fn collect(
on_complete callback: fn(String, Int) -> Nil,
) -> Stdio
Collect all output and call the callback when the process finishes. The callback receives the complete output as a String and the exit status code.
This is useful when you want to process all output at once rather than streaming it.
Example
stdio.collect(fn(output, status_code) {
io.println("Process exited with code: " <> int.to_string(status_code))
io.println("Output: " <> output)
})
pub fn inherit() -> Stdio
Inherit stdio streams from the parent process. The child process will share stdin, stdout, and stderr with the parent.
This is useful for interactive programs like text editors, REPLs, or any
program that needs direct terminal access. When using inherit() with
run(), the captured output will be empty since output goes directly to
the terminal.
Important: On the Erlang target, you must start your application with
the -noshell flag for inherited stdio to work properly with interactive
programs.
For example: erl -noshell -pa build/dev/erlang/*/ebin -run module main
Example
// Launch vim - user can interact with it directly
child_process.new("vim")
|> child_process.arg("file.txt")
|> child_process.stdio(stdio.inherit())
|> child_process.run()
pub fn lines(on_line callback: fn(String) -> Nil) -> Stdio
Stream output line-by-line.
The callback receives complete lines as Strings, including their newline character. Note that if the last line does not contain a newline character, the received string won’t contain one either.
Important: If the process outputs partial lines (data without a newline), that data will be buffered until either a newline arrives or the process exits. When the process exits, any remaining buffered data will be delivered as a final callback, even without a trailing newline.
Example
stdio.lines(fn(line) {
io.println(line)
})