Skip to content

Instantly share code, notes, and snippets.

@mattn
Forked from tokuhirom/gist:188418
Created September 17, 2009 09:26
Show Gist options
  • Save mattn/188420 to your computer and use it in GitHub Desktop.
Save mattn/188420 to your computer and use it in GitHub Desktop.
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