Re: Problem with Win32::Console and END block.

From: Brian Helterline (brian_helterline_at_hp.com)
Date: 12/16/03

  • Next message: G: "Re: FILE parsing problems"
    Date: Tue, 16 Dec 2003 11:50:40 -0800
    
    

    "Richard S Beckett" <spikeywan@bigfoot.com.delete.this.bit> wrote in message
    news:brnhku$k0i$1@newshost.mot.com...
    > I want to set my dos window up with 80 cols and 100 lines, but when I do I
    > break my END block. Here's an example...
    >
    > use strict;
    > use warnings;
    > $| =1;
    >
    > # use Win32::Console;
    > # my $BUFFER = new Win32::Console(STD_OUTPUT_HANDLE);
    > # $BUFFER->Size(80,100);
    >
    > for (1..5) {print "."; sleep 1}
    > exit;
    > END {print "\n\nPress Enter\n"; <STDIN>;}
    >
    > In the above form it works. BUT remove the comments from the first 2 or 3
    > (commented) lines, and the PRINT statement in the END block stops working.
    > The <STDIN> still works, though.
    >
    > What am I doing wrong _this_ time? ;-)
    >

    Richard,
    Win32::Console takes an "all or nothing" approach so when a console window
    is closed or destroyed, STDIN/STDOUT get closed.
    If your program wants to continue "outside" of the console, then you need
    to dup it before calling new. The code below works (AS 5.6.1)

    use strict;
    use warnings;

    use Win32::Console;

    BEGIN {
    $| =1;
    open(CPY, ">&STDOUT") or die "can't dup STDOUT $!";
    select CPY;
    $| = 1;
    }
    print "\nOutput to STDOUT before Console.\n";

    my $BUFFER = new Win32::Console(STD_OUTPUT_HANDLE);
    $BUFFER->Size(80,100);

    for (1..5) {print "."; sleep 1}
    open(STDOUT, ">&CPY") or die "can't reopen STDOUT $!";
    select STDOUT;
    $|=1;
    print "\nOutput to STDOUT after Console.\n";
    exit;
    END {print CPY "\n\nPress Enter\n"; <STDIN>;}


  • Next message: G: "Re: FILE parsing problems"

    Relevant Pages

    • Numeric IP addresses
      ... use strict; ... use warnings; ... use Socket; ... exit unless; ...
      (perl.beginners)
    • Re: Please help with convoluted script
      ... use warnings; ... use strict; ... foreach my $i { ...
      (perl.beginners)
    • Re: fork and taint
      ... use strict; ... use warnings; ... I only get the "before fork ok" in browser and perl.exe crashes, ... exit 0;} ...
      (comp.lang.perl.misc)
    • Re: fork and taint
      ... use strict; ... use warnings; ... I only get the "before fork ok" in browser and perl.exe crashes, ... exit 0;} ...
      (comp.lang.perl.misc)
    • Re: ANSI colors and the space they take.
      ... which I use when I want to output something to STDOUT from ... > use strict; ... > use warnings; ... > sub output { ...
      (comp.lang.perl.misc)