pub struct WslProcess {
pub stdin: Option<ChildStdin>,
pub stdout: Option<ChildStdout>,
pub stderr: Option<ChildStderr>,
/* private fields */
}Fields§
§stdin: Option<ChildStdin>§stdout: Option<ChildStdout>§stderr: Option<ChildStderr>Implementations§
Source§impl WslProcess
impl WslProcess
Sourcepub fn wait(self) -> Result<ExitStatus, WslError>
pub fn wait(self) -> Result<ExitStatus, WslError>
Examples found in repository?
examples/basic_usage.rs (line 57)
5fn run_command(wsl: &Wsl2, distro_uuid: uuid::Uuid) -> Result<(), Box<dyn std::error::Error>> {
6 println!("Running command...");
7 let result = wsl.launch(
8 distro_uuid,
9 "/bin/echo",
10 &["echo", "Hello, world!"],
11 None,
12 "root",
13 );
14 let mut process = {
15 match result {
16 Ok(process) => {
17 println!("Successfully ran command: {process:?}");
18 process
19 }
20 Err(e) => {
21 eprintln!("Failed to run command: {:?}", e);
22 return Err(e.into());
23 }
24 }
25 };
26
27 let stdout = process.stdout.take().unwrap();
28 let stderr = process.stderr.take().unwrap();
29
30 let stdout_thread = std::thread::spawn(move || {
31 let reader = std::io::BufReader::new(stdout);
32 for line in reader.lines() {
33 match line {
34 Ok(line) => println!("stdout: {}", line),
35 Err(e) => {
36 eprintln!("Error reading stdout: {}", e);
37 return;
38 }
39 }
40 }
41 });
42
43 let stderr_thread = std::thread::spawn(move || {
44 let reader = std::io::BufReader::new(stderr);
45 for line in reader.lines() {
46 match line {
47 Ok(line) => println!("stderr: {}", line),
48 Err(e) => {
49 eprintln!("Error reading stderr: {}", e);
50 return;
51 }
52 }
53 }
54 });
55
56 println!("Waiting for process to finish...");
57 let status = process.wait()?;
58 println!("Process finished with status: {status:?}");
59
60 stdout_thread.join().unwrap();
61 stderr_thread.join().unwrap();
62
63 Ok(())
64}Trait Implementations§
Source§impl Debug for WslProcess
impl Debug for WslProcess
Auto Trait Implementations§
impl Freeze for WslProcess
impl !RefUnwindSafe for WslProcess
impl Send for WslProcess
impl !Sync for WslProcess
impl Unpin for WslProcess
impl !UnwindSafe for WslProcess
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more