Skip to content

Instantly share code, notes, and snippets.

@riywo
Created March 16, 2011 17:06
Show Gist options
  • Save riywo/872848 to your computer and use it in GitHub Desktop.
Save riywo/872848 to your computer and use it in GitHub Desktop.
ファイルハンドルを途中で読み込み止めるにはどうするのがいいのかな。。。
use strict;
use warnings;
use IO::Handle;
my ($parent_in, $parent_out);
my ($child_in, $child_out);
pipe $parent_out, $child_in;
pipe $child_out, $parent_in;
$parent_in->autoflush(1);
$child_in->autoflush(1);
if (my $pid = fork) {
close $parent_in; close $parent_out;
print $child_in 'select @@version;'."\n";
while (my $line = <$child_out>) {
print $line;
}
# waiting...
# not execute below..
print $child_in 'show databases;'."\n";
while (my $line = <$child_out>) {
print $line;
}
close $child_in;
close $child_out;
waitpid($pid,0);
} else {
die "cannot fork: $!" unless defined $pid;
close $child_in; close $child_out;
open STDOUT, '>&', $parent_in;
open STDIN, '<&', $parent_out;
exec "mysql -n -uroot" or exit;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment