Skip to content

Instantly share code, notes, and snippets.

@kaz-utashiro
Last active November 18, 2019 03:19
Show Gist options
  • Save kaz-utashiro/7084f773b14851466abf to your computer and use it in GitHub Desktop.
Save kaz-utashiro/7084f773b14851466abf to your computer and use it in GitHub Desktop.
Perl で子プロセスが入力を読めない問題 ref: https://qiita.com/kaz-utashiro/items/80fc83e56e645f19e927
$_ = do { local $/; <> };
if (open(CHLD, '|-') == 0) {
print <>;
exit;
}
print CHLD $_;
$_ = do { local $/; <> };
if (open(CHLD, '|-') == 0) {
exec "cat" or warn $!;
exit;
}
print CHLD $_;
if (open(CHLD, '|-') == 0) {
print <>;
exit;
}
$_ = do { local $/; <> };
print CHLD $_;
@_ = <>;
if (open(CHLD, '|-') == 0) {
print <>;
exit;
}
print CHLD @_;
@_ = <>;
warn "eof\n" if eof STDIN;
if (open(CHLD, '|-') == 0) {
print <>;
exit;
}
print CHLD @_;
$_ = do { local $/; <> };
if (open(CHLD, '|-') == 0) {
<> if eof STDIN;
print <>;
exit;
}
print CHLD $_;
$_ = do { local $/; <> };
if (open(CHLD, '|-') == 0) {
open STDIN, '<&', 0 if eof STDIN;
print <>;
exit;
}
print CHLD $_;
$_ = do { local $/; <> };
pipe PIN, POUT or die;
if (fork == 0) {
close STDIN;
open STDIN, '<&PIN';
close PIN;
close POUT;
print <>;
exit;
}
close PIN;
print POUT $_;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment