Representation of a running or exited child process.
This structure is used to represent and manage child processes. A child process is created via the Command struct, which configures the spawning process and can itself be constructed using a builder-style interface.
NOTE: If you do not ensure the
Child
has exited then it will continue to run.
More details see: https://doc.rust-lang.org/std/process/struct.Child.html
Example
use std.process.Command;
fn main() throws {
let child = try Command.new("echo").arg("hello").run();
let status = try child.wait();
assert_eq status, 0;
}
[src]
pub fn id(self): int? {
return (self as _Child).id();
}
Returns the OS-assigned process identifier associated with this child.
[src]
pub fn id(self): int? {
return (self as _Child).id();
}
Returns the OS-assigned process identifier associated with this child.
Returns the OS-assigned process identifier associated with this child.
Once the child has been polled to completion this will return None. This is done to avoid confusion on platforms like Unix where the OS identifier could be reused once the process has completed.
use std.process.Command;
fn main() throws {
let child = try Command.new("echo").arg("hello").run();
println(`pid: ${child.id():?}`);
}
[src]
pub fn kill(self) throws IoError {
try (self as _Child).kill();
}
Forces the child process to exit. If the child has already exited, do nothing.
[src]
pub fn kill(self) throws IoError {
try (self as _Child).kill();
}
Forces the child process to exit. If the child has already exited, do nothing.
Forces the child process to exit. If the child has already exited, do nothing.
This is equivalent to sending a SIGKILL
on Unix platforms.
use std.process.Command;
fn main() throws {
let child = try Command.new("echo").arg("hello").run();
try child.kill();
}
[src]
pub fn wait(self): int? throws IoError {
return try (self as _Child).wait();
}
Waits for the child to exit completely, returning the status that it exited with.
This function will continue to have the same return value after it has been called at least once.
[src]
pub fn wait(self): int? throws IoError {
return try (self as _Child).wait();
}
Waits for the child to exit completely, returning the status that it exited with. This function will continue to have the same return value after it has been called at least once.
Waits for the child to exit completely, returning the status that it exited with. This function will continue to have the same return value after it has been called at least once.
The stdin handle to the child process, if any, will be closed before waiting. This helps avoid deadlock: it ensures that the child does not block waiting for input from the parent, while the parent waits for the child to exit.
use std.process.Command;
fn main() throws {
let child = try Command.new("echo").arg("hello").run();
let status = try child.wait();
assert_eq status, 0;
}
wait_with_output
pub fn wait_with_output(self): Output throws IoError
[src]
pub fn wait_with_output(self): Output throws IoError {
let output = try (self as _Child).wait_with_output();
return Output {
stdout: output.stdout,
stderr: output.stderr,
status: output.status,
};
}
Waits for the child to exit and collect all remaining
output on the stdout/stderr handles, returning an Output
instance.
wait_with_output
pub fn wait_with_output(self): Output throws IoError
[src]
pub fn wait_with_output(self): Output throws IoError {
let output = try (self as _Child).wait_with_output();
return Output {
stdout: output.stdout,
stderr: output.stderr,
status: output.status,
};
}
Waits for the child to exit and collect all remaining
output on the stdout/stderr handles, returning an Output
instance.
Waits for the child to exit and collect all remaining
output on the stdout/stderr handles, returning an Output
instance.
The stdin handle to the child process, if any, will be closed before waiting. This helps avoid deadlock: it ensures that the child does not block waiting for input from the parent, while the parent waits for the child to exit.
By default, stdin, stdout and stderr are inherited from the parent.
In order to capture the output into this Output
it is
necessary to create new pipes between parent and child. Use
stdout("piped")
or stderr("piped")
, respectively.
Examples
use std.process.Command;
fn main() throws {
let child = try Command.new("notfound").stdout("piped").run();
// This will throws an error because the command is not valid
try child.wait_with_output();
let child = try Command.new("echo").arg("hello").run();
let output = try child.wait_with_output();
assert_eq output.stdout.to_string(), "hello\n";
}
stdin
pub fn stdin(self): ChildStdin?
[src]
pub fn stdin(self): ChildStdin? {
if ((self as _Child).has_stdin()) {
return ChildStdin { child: self };
} else {
return nil;
}
}
The handle for writing to the child’s standard input (stdin)
stdin
pub fn stdin(self): ChildStdin?
[src]
pub fn stdin(self): ChildStdin? {
if ((self as _Child).has_stdin()) {
return ChildStdin { child: self };
} else {
return nil;
}
}
The handle for writing to the child’s standard input (stdin)
The handle for writing to the child’s standard input (stdin)
stdout
pub fn stdout(self): ChildStdout?
[src]
pub fn stdout(self): ChildStdout? {
if ((self as _Child).has_stdout()) {
return ChildStdout { child: self };
} else {
return nil;
}
}
The handle for reading from the child’s standard output (stdout)
stdout
pub fn stdout(self): ChildStdout?
[src]
pub fn stdout(self): ChildStdout? {
if ((self as _Child).has_stdout()) {
return ChildStdout { child: self };
} else {
return nil;
}
}
The handle for reading from the child’s standard output (stdout)
The handle for reading from the child’s standard output (stdout)
stderr
pub fn stderr(self): ChildStderr?
[src]
pub fn stderr(self): ChildStderr? {
if ((self as _Child).has_stderr()) {
return ChildStderr { child: self };
} else {
return nil;
}
}
The handle for reading from the child’s standard error (stderr)
stderr
pub fn stderr(self): ChildStderr?
[src]
pub fn stderr(self): ChildStderr? {
if ((self as _Child).has_stderr()) {
return ChildStderr { child: self };
} else {
return nil;
}
}
The handle for reading from the child’s standard error (stderr)
The handle for reading from the child’s standard error (stderr)