std.sys.ChildProcess
class pub ChildProcess
A running or exited child OS process.
Fields
stdin
let pub @stdin: Option[Stdin]
A handle to the captured input stream of the child process.
stdout
let pub @stdout: Option[Stdout]
A handle to the captured output stream of the child process.
stderr
let pub @stderr: Option[Stderr]
A handle to the captured error stream of the child process.
Instance methods
try_wait
Show source codeHide source code
fn pub try_wait -> Result[Option[ExitStatus], Error] {
match sys.try_wait(@id) {
case Ok(None) -> Result.Ok(Option.None)
case Ok(Some(n)) -> Result.Ok(Option.Some(ExitStatus(n)))
case Error(e) -> Result.Error(e)
}
}
fn pub try_wait -> Result[Option[ExitStatus], Error]
Returns the exit status of the child process without blocking the calling process.
If the process is still running, an Option.None
is returned. If the
process exited, an Option.Some(ExitStatus)
is returned.
This method doesn't close STDIN before waiting.
wait
Show source codeHide source code
fn pub mut wait -> Result[ExitStatus, Error] {
drop(@stdin := Option.None)
sys.wait(@id).map(fn (v) { ExitStatus(v) })
}
fn pub mut wait -> Result[ExitStatus, Error]
Waits for the child process to finish running, and returns an ExitStatus
containing the exit status.
The child's STDIN stream (if any) is closed before waiting, avoiding deadlocks caused by child processes waiting for input from the parent while the parent waits for the child to exit.
Note that if you try to read from STDOUT or STDERR before calling
ChildProcess.wait
without closing STDIN first, the parent process may
still deadlock as the read might not return and thus prevent
ChildProcess.wait
from first closing STDIN.
To prevent this from happening, always make sure STDIN is closed before
reading from STDOUT or STDERR if the read happens before a call to
ChildProcess.wait
.