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 |
#4 in #pseudo
49 downloads per month
Used in 2 crates
(via libshpool)
24KB
450 lines
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.
lib.rs
:
PTY
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");
}
}
Dependencies
~61–340KB