#pty #fork #tty #terminal #pseudo

shpool_pty

Fork with new pseudo-terminal (PTY)

5 unstable releases

Uses old Rust 2015

0.3.1 Apr 2, 2024
0.3.0 Nov 8, 2023
0.2.1 Nov 7, 2023
0.2.0 Nov 7, 2023
0.1.0 Sep 22, 2023

#6 in #pseudo-terminal

Download history 79/week @ 2025-03-10 79/week @ 2025-03-17 200/week @ 2025-03-24 74/week @ 2025-03-31 81/week @ 2025-04-07 53/week @ 2025-04-14 74/week @ 2025-04-21 65/week @ 2025-04-28 45/week @ 2025-05-05 57/week @ 2025-05-12 28/week @ 2025-05-19 34/week @ 2025-05-26 38/week @ 2025-06-02 103/week @ 2025-06-09 22/week @ 2025-06-16 26/week @ 2025-06-23

191 downloads per month
Used in 2 crates (via libshpool)

MIT license

24KB
450 lines

PTY

Crate docs-badge license-badge travis-badge

The pty crate provides pty::fork(). That makes a parent process fork with new pseudo-terminal (PTY).

This crate depends on followings:

  • libc library
  • POSIX environment

Usage

Add this to your Cargo.toml:

[dependencies]
pty = "0.2"

and this to your crate root:

extern crate shpool_pty;

pty::fork()

This function returns pty::Child. It represents the child process and its PTY.

For example, the following code spawns tty(1) command by pty::fork() and outputs the result of the command.

extern crate shpool_pty;
extern crate libc;

use std::ffi::CString;
use std::io::Read;
use std::process::{Command};

use shpool_pty::fork::*;

fn main() {
  let fork = Fork::from_ptmx().unwrap();

  if let Some(mut master) = fork.is_parent().ok() {
    // Read output via PTY master
    let mut output = String::new();

    match master.read_to_string(&mut output) {
      Ok(_nread) => println!("child tty is: {}", output.trim()),
      Err(e)     => panic!("read error: {}", e),
    }
  }
  else {
    // Child process just exec `tty`
    Command::new("tty").status().expect("could not execute tty");
  }
}

shpool_pty

A fork of the pty crate with some extra features added to help implement shpool. See the main pty crate for more info.

Dependencies

~63–345KB