#crt #process #windows #spawn

winspawn

Spawn process for passing Universal CRT's file descriptor on windows

2 releases

0.1.1 Jul 1, 2021
0.1.0 Jun 28, 2021

#7 in #crt

22 downloads per month
Used in chrome-remote-interface

MIT/Apache

145KB
5K SLoC

winspawn

Spawn process for passing Universal CRT's file descriptor on windows.

Using _spawn & _dup.

Example

use winspawn::{move_fd, spawn, FileDescriptor, Mode};

use std::mem;
use std::io;
use std::fs;
use std::os::windows::io::IntoRawHandle;

fn main() -> io::Result<()> {
    let file = fs::File::open("Cargo.toml")?;
    let handle = file.into_raw_handle();
    let fd = FileDescriptor::from_raw_handle(handle, Mode::ReadOnly)?;

    let mut proc = move_fd(&fd, 3, |_| {
        // print fd 3 stat
        spawn("python", ["-c", r#""import os; print(os.stat(3))""#])
    })?;

    let exit_code = proc.wait()?;
    assert_eq!(0, exit_code);

    Ok(())
}

License: MIT/Apache-2.0


lib.rs:

Spawn process for passing Universal CRT's file descriptor on windows.

Using _spawn & _dup.

Example

use winspawn::{move_fd, spawn, FileDescriptor, Mode};

use std::mem;
use std::io;
use std::fs;
use std::os::windows::io::IntoRawHandle;

fn main() -> io::Result<()> {
    let file = fs::File::open("Cargo.toml")?;
    let fd = FileDescriptor::from_raw_handle(file, Mode::ReadOnly)?;

    let mut proc = move_fd(&fd, 3, |_| {
        // print fd 3 stat
        spawn("python", ["-c", r#""import os; print(os.stat(3))""#])
    })?;

    let exit_code = proc.wait()?;
    assert_eq!(0, exit_code);

    Ok(())
}

Dependencies

~124MB
~2M SLoC