Struct ptyprocess::PtyProcess[][src]

pub struct PtyProcess { /* fields omitted */ }
Expand description

PtyProcess controls a spawned process and communication with this.

It implements std::io::Read and std::io::Write to communicate with a child.

use ptyprocess::PtyProcess;
use std::io::Write;
use std::process::Command;

let mut process = PtyProcess::spawn(Command::new("cat")).unwrap();
process.write_all(b"Hello World").unwrap();
process.flush().unwrap();

Implementations

Spawns a child process and create a PtyProcess.

    let proc = PtyProcess::spawn(Command::new("bash"));

Returns a pid of a child process

Returns a file representation of a PTY, which can be used to communicate with it.

Safety

Be carefull changing a descriptors inner state (e.g fcntl) because it affects all structures which use it.

Be carefull using this method in async mode. Because descriptor is set to a non-blocking mode which may be unexpected.

In future ut can be private for async feature if it will be considered an issue.

Example
use ptyprocess::PtyProcess;
use std::{process::Command, io::{BufReader, LineWriter}};

let mut process = PtyProcess::spawn(Command::new("cat")).unwrap();
let pty = process.get_pty_handle().unwrap();
let mut writer = LineWriter::new(&pty);
let mut reader = BufReader::new(&pty);

Get window size of a terminal.

Default size is 80x24.

Sets a terminal size.

Waits until a echo settings is setup.

The function returns true if an echo setting is setup.

Sets a echo setting for a terminal

Returns true if a underline fd connected with a TTY.

Set the pty process’s terminate approach delay.

Status returns a status a of child process.

Kill sends a signal to a child process.

The operation is non-blocking.

Signal is an alias to PtyProcess::kill.

Wait blocks until a child process exits.

It returns a error if the child was DEAD or not exist at the time of a call.

If you need to verify that a process is dead in non-blocking way you can use is_alive method.

Checks if a process is still exists.

It’s a non blocking operation.

Keep in mind that after calling this method process might be marked as DEAD by kernel, because a check of its status. Therefore second call to Self::status or Self::is_alive might return a different status.

Try to force a child to terminate.

This returns true if the child was terminated. and returns false if the child could not be terminated.

It makes 4 tries getting more thorough.

  1. SIGHUP
  2. SIGCONT
  3. SIGINT
  4. SIGTERM

If “force” is true then moves onto SIGKILL.

Trait Implementations

Formats the value using the given formatter. Read more

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.