Created
March 16, 2011 17:06
-
-
Save riywo/872848 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
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