Created
August 1, 2009 04:31
-
-
Save jrockway/159568 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[~] 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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