-
-
Save mattn/188420 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
mattn: pipe() は Perl の場合、win32 でもうごきますか? | |
動きます。 | |
----------------------------------------- | |
#!/usr/bin/perl -w | |
use IO::Handle; | |
pipe(PARENTREAD, PARENTWRITE); | |
pipe(CHILDREAD, CHILDWRITE); | |
PARENTWRITE->autoflush(1); | |
CHILDWRITE->autoflush(1); | |
if ($child = fork) { | |
close CHILDREAD; | |
close PARENTWRITE; | |
print CHILDWRITE "34+56;\n"; | |
chomp($result = <PARENTREAD>); | |
print "白ヤギさんから答えが来た: $result\n"; | |
close PARENTREAD; | |
close CHILDWRITE; | |
waitpid($child,0); | |
} else { | |
close PARENTREAD; | |
close CHILDWRITE; | |
chomp($calculation = <CHILDREAD>); | |
print "黒ヤギさんから計算式来た: $calculation\n"; | |
$result = eval "$calculation"; | |
print PARENTWRITE "$result\n"; | |
close CHILDREAD; | |
close PARENTWRITE; | |
exit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment