Struct WslProcess

Source
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

Source

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for WslProcess

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.