Struct conpty::Process

source ·
pub struct Process { /* private fields */ }
Expand description

The structure is resposible for interations with spawned process. It handles IO and other operations related to a spawned process.

Implementations§

source§

impl Process

source

pub fn spawn(command: Command) -> Result<Self, Error>

Spawn a given command.

use std::io::prelude::*;
use std::process::Command;
use conpty::Process;

let mut cmd = Command::new("cmd");
cmd.args(&["/C", "echo Hello World"]);

let mut proc = Process::spawn(cmd).unwrap();
let mut reader = proc.output().unwrap();

let mut buf = [0; 1028];
let n = reader.read(&mut buf).unwrap();

assert!(String::from_utf8_lossy(&buf).contains("Hello World"));
source

pub fn pid(&self) -> u32

Returns a process’s pid.

source

pub fn wait(&self, timeout_millis: Option<u32>) -> Result<u32, Error>

Waits before process exists.

source

pub fn is_alive(&self) -> bool

Is alive determines if a process is still running.

IMPORTANT: Beware to use it in a way to stop reading when is_alive is false.

source

pub fn resize(&mut self, x: i16, y: i16) -> Result<(), Error>

Resizes virtual terminal.

source

pub fn exit(&mut self, code: u32) -> Result<(), Error>

Termianates process with exit_code.

source

pub fn set_echo(&mut self, on: bool) -> Result<(), Error>

Sets echo mode for a session.

source

pub fn input(&mut self) -> Result<PipeWriter, Error>

Returns a pipe writer to conPTY.

source

pub fn output(&mut self) -> Result<PipeReader, Error>

Returns a pipe reader from conPTY.

Trait Implementations§

source§

impl Debug for Process

source§

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

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

impl Drop for Process

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.