Control a Shell With pty-shell

E39aeab4407ea02102f75584618549a4?s=47 Hibariya Hi
December 23, 2015

Control a Shell With pty-shell

Introducing pty-shell which is an extension of pty crate


Hibariya Hi

December 23, 2015


  1. Control a Shell With pty-shell Rust of Us - Chapter

    5 2015-12-23 @hibariya
  2. Hi, there. • Hika Hibariya • @hibariya •

  3. pty

  4. pty: Fork With a New TTY • pty::fork() •

    Substitute of PTY.spawn
  5. pty: Fork With a New TTY

  6. It’s Not Enough My original purpose is to control STDIO

    of a shell process. To accomplish it, I have to do followings. • Do exec a shell command (e.g. bash) • Make parent process enter raw-mode • Connect parent STDIO to child STDIO • Notify winsize changes from parent to child
  7. pty-shell

  8. pty-shell: A Dedicated Extension For Shell

  9. pty-shell: Control STDIO of a Shell Spawns a new

    shell and connects to its parent’ s STDIO. Then makes the parent act as proxy. Anyway, you can hook the INPUT/OUTPUT of a shell process. For example: you can play any sound effect and/or you can record or share output of the terminal.
  10. What To Use? For example: Terminal sharing tool

  11. Do Something On INPUT/OUTPUT

  12. Play Sound Effects

  13. Send Messages

  14. Record It

  15. Anything

  16. use pty; use pty_shell::{PtyProxy, PtyHandler}; struct MyHandler; impl PtyHandler for

    MyHandler { fn input(&mut self, input: Vec<u8>) { // do something with input } fn output(&mut self, output: Vec<u8>) { // do something with output } }
  17. fn main() { let child = pty::fork().unwrap(); child.exec("bash"); child.proxy(MyHandler); child.wait();

  18. extern crate pty_shell;