G
George Glynn
Perl 5.8.5 on Fedora Core 3...
Can anyone tell me why my SIGPIPE handler doesn't run until I hit the enter
key when running this program from a TTY?
1: #!/usr/bin/perl
2:
3: use FileHandle;
4: use IPC::Open2;
5:
6: sub pipeHandler {
7: die("I piped");
8: }
9:
10: $SIG{PIPE} = \&pipeHandler;
11:
12: $pid = open2( \*FROMPROC, \*TOPROC, "/path/to/nonexistent/program");
13: TOPROC->autoflush();
14:
15: print TOPROC "Garbage in...";
16: print <FROMPROC>;
17:
18: while(<STDIN>) {
19: print TOPROC $_;
20: print <FROMPROC>;
21: }
I get the error message:
open2: exec of /path/to/nonexistent/program failed at foowrap line 12
right away, but the program sits waiting until I hit the enter key, then
dies and prints on STDERR:
I piped at script_name line 7, <STDIN> line 1.
Why didn't it hit the SIGPIPE handler trying to write to TOPROC on line 15?
I've also tried trapping __DIE__ with the following handler:
a: sub dieHandler {
b: die("I died");
c: }
This handler runs right away, and the message:
I died at script_name line b.
prints instead of the "open2: exec ... failed ..." message, as one would
expect, but then it still sits there waiting for me to hit enter again, at
which point it prints:
I died at script_name line b, <STDIN> line 1.
I'm sure I'm just missing the subtleties of IPC, so can anyone clue me in as
to what's happening here?
In case you're wondering, I ultimately want to have the program die right
away if the exec in the open2() program fails.
Can anyone tell me why my SIGPIPE handler doesn't run until I hit the enter
key when running this program from a TTY?
1: #!/usr/bin/perl
2:
3: use FileHandle;
4: use IPC::Open2;
5:
6: sub pipeHandler {
7: die("I piped");
8: }
9:
10: $SIG{PIPE} = \&pipeHandler;
11:
12: $pid = open2( \*FROMPROC, \*TOPROC, "/path/to/nonexistent/program");
13: TOPROC->autoflush();
14:
15: print TOPROC "Garbage in...";
16: print <FROMPROC>;
17:
18: while(<STDIN>) {
19: print TOPROC $_;
20: print <FROMPROC>;
21: }
I get the error message:
open2: exec of /path/to/nonexistent/program failed at foowrap line 12
right away, but the program sits waiting until I hit the enter key, then
dies and prints on STDERR:
I piped at script_name line 7, <STDIN> line 1.
Why didn't it hit the SIGPIPE handler trying to write to TOPROC on line 15?
I've also tried trapping __DIE__ with the following handler:
a: sub dieHandler {
b: die("I died");
c: }
This handler runs right away, and the message:
I died at script_name line b.
prints instead of the "open2: exec ... failed ..." message, as one would
expect, but then it still sits there waiting for me to hit enter again, at
which point it prints:
I died at script_name line b, <STDIN> line 1.
I'm sure I'm just missing the subtleties of IPC, so can anyone clue me in as
to what's happening here?
In case you're wondering, I ultimately want to have the program die right
away if the exec in the open2() program fails.