Skip to content

Instantly share code, notes, and snippets.

@jrockway
Created August 1, 2009 04:31
Show Gist options
  • Save jrockway/159568 to your computer and use it in GitHub Desktop.
Save jrockway/159568 to your computer and use it in GitHub Desktop.
[~] 0 (jon@bar)
$ perl slave.pl
Got 'f'
Got 'o'
Got 'o'
Got ''
Got ''
Got ''
Got 'b'
Got 'z'
Got 'z'
Got '
'
Parent said: (b)(z)(z)
#!/usr/bin/env perl
use strict;
use warnings;
use feature ':5.10';
use IO::Pty;
use Term::ReadKey;
my $pty = IO::Pty->new;
#$pty->set_raw;
my $slave = $pty->slave;
local $|=1;
if(fork){
my $line = <$slave>;
$line =~ s/(.)/($1)/g;
print "Parent said: $line";
}
else {
$pty->close_slave;
ReadMode 4; # Turn off controls keys
foo: while (my $key = ReadKey(0)) {
print "Got '$key'\n";
last foo if $key eq 'a';
print {$pty} $key;
}
ReadMode 0; # Reset tty mode before exiting
}
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment