writing to a pipe on win32

Discussion in 'Perl' started by momena, Jul 23, 2004.

  1. momena

    momena Guest

    Hi experts,
    I need to write a perl script that will be called from a series of
    executables chained thru pipes that read from STDIN and writes to
    STDOUT. The following code works fine under regular circumstance. But
    when there is a error down the pipe in one of the executables, the
    pipe closes and then this script just exits. It does not print line
    14. The troublesome line is line number 17. If I comment it out, the
    script completes. From my very little perl knowledge, I was thinking
    that in line 17, when we call "print $_" and the pipe broke due to the
    error in another executable, it would generate SIGPIPE, but I get no
    signal. Does SIGPIPE work on windows ?

    1 sub signalhandler
    2 {
    3 print STDERR "*Received a SIG$_[0]\n";
    4 }

    5 my $Tmp_File = "c:/test_dir/testFile";

    6 open(IN_FILE, ">$Tmp_File") || die "Open file error: $!";
    7 binmode (IN_FILE);

    8 while (<STDIN>) {
    9 print IN_FILE ;
    10 }
    11 close(IN_FILE);

    12 use sigtrap qw{handler signalhandler normal-signals
    error-signals};

    13 open(OUT_FILE, "$some_other_executable $Tmp_File |") || die
    "Fork error: $!";
    14 print STDERR "Opened file OUT_FILE!!\n";
    15 binmode (OUT_FILE);
    16 while (<OUT_FILE>) {
    17 print $_;
    18 }
    19 unlink ($Tmp_File) || die "Remove file error: $!";

    Thanks in advance.

    Momena
     
    momena, Jul 23, 2004
    #1
    1. Advertising

  2. momena

    momena Guest

    (momena) wrote in message news:<>...
    > Hi experts,
    > I need to write a perl script that will be called from a series of
    > executables chained thru pipes that read from STDIN and writes to
    > STDOUT. The following code works fine under regular circumstance. But
    > when there is a error down the pipe in one of the executables, the
    > pipe closes and then this script just exits. It does not print line
    > 14. The troublesome line is line number 17. If I comment it out, the
    > script completes. From my very little perl knowledge, I was thinking
    > that in line 17, when we call "print $_" and the pipe broke due to the
    > error in another executable, it would generate SIGPIPE, but I get no
    > signal. Does SIGPIPE work on windows ?
    >
    > 1 sub signalhandler
    > 2 {
    > 3 print STDERR "*Received a SIG$_[0]\n";
    > 4 }
    >
    > 5 my $Tmp_File = "c:/test_dir/testFile";
    >
    > 6 open(IN_FILE, ">$Tmp_File") || die "Open file error: $!";
    > 7 binmode (IN_FILE);
    >
    > 8 while (<STDIN>) {
    > 9 print IN_FILE ;
    > 10 }
    > 11 close(IN_FILE);
    >
    > 12 use sigtrap qw{handler signalhandler normal-signals
    > error-signals};
    >
    > 13 open(OUT_FILE, "$some_other_executable $Tmp_File |") || die
    > "Fork error: $!";
    > 14 print STDERR "Opened file OUT_FILE!!\n";
    > 15 binmode (OUT_FILE);
    > 16 while (<OUT_FILE>) {
    > 17 print $_;
    > 18 }
    > 19 unlink ($Tmp_File) || die "Remove file error: $!";
    >
    > Thanks in advance.
    >
    > Momena


    I ran it on unix (hpux) and I get SIGTERM, not SIGPIPE. Now that I
    think about it again, it makes sense not to get a SIGPIPE, because I
    am not directly writing to a pipe in line 17, even though other end os
    STDOUT is a pipe. But in windows I get no signals. It seems very wrong
    to me. Any comments ?
     
    momena, Jul 28, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. lee, wonsun
    Replies:
    1
    Views:
    498
    Jack Klein
    Nov 2, 2004
  2. Daniel Berger

    named pipe problem on Win32

    Daniel Berger, Nov 21, 2003, in forum: Ruby
    Replies:
    1
    Views:
    150
    Park Heesob
    Nov 22, 2003
  3. Daniel Berger

    [ANN] win32-pipe 0.0.1

    Daniel Berger, Nov 22, 2003, in forum: Ruby
    Replies:
    0
    Views:
    143
    Daniel Berger
    Nov 22, 2003
  4. Replies:
    1
    Views:
    237
    Ben Morrow
    Jun 2, 2004
  5. momena

    writing to a pipe on win32

    momena, Jul 26, 2004, in forum: Perl Misc
    Replies:
    0
    Views:
    86
    momena
    Jul 26, 2004
Loading...

Share This Page