Win32::Console is frustrating to use because it exposes you to the frustrations inherent in Windows!

There are some problems I see in your code.
    my $con_current = Win32::Console->new(GENERIC_READ | GENERIC_WRITE);
I can't get this to work. What works for me is  STD_OUTPUT_HANDLE as the argument to new().
    $con_current->WriteRect($rect,$left, $top, $right, $bottom )or die 'write Win32::Console failed';
This will write the rectangle back to the console window at the exact position from which it was read, and there will be no visible effect!

Here's a version of your code modified to produce some effect in the console window. The rectangle read by  ReadRect() has its coordinates shifted so a difference can be seen when written back by  WriteRect(). (You might also try changing color, etc., attributes to produce a noticeable change.)

use Win32::Console qw(STD_OUTPUT_HANDLE GENERIC_READ GENERIC_WRITE); use Data::Dump qw(dd); ;; my $con_current = Win32::Console->new(STD_OUTPUT_HANDLE) ; $con_current or die 'new Win32::Console failed'; ;; my ($left, $top, $right, $bottom) = $con_current->Window; printf qq{Dimensions left %d top %d right %d bottom %d \n}, $left, $top, $right, $bottom; ;; my $rect = $con_current->ReadRect($left, $top, $right, $bottom); $rect or die 'read Win32::Console failed'; ;; $_ += 2 for $top, $bottom, $left, $right; $con_current->WriteRect($rect,$left, $top, $right, $bottom )or die 'wr +ite Win32::Console failed';

The intent of my original code was to produce a print-able string that might also be saved to a file. I see now that the
    $rect =~ s{ \0\a\0  } ''xmsg;
substitution to strip out the attribute stuff was too specific to my console configuration. Try the more general
    $rect =~ s{ \G . \K ... } ''xmsg;
(Note: This regex needs Perl version 5.10+ for the  \K regex operator. If you have a pre-5.10 Perl, I can supply an alternate regex.)

All this is still very kludgy, but I hope it may be of some interest or use to you. And again, good luck!


Give a man a fish:  <%-{-{-{-<


In reply to Re^5: Saving a Perl session to a file - Win32::Console usabability by AnomalousMonk
in thread Saving a Perl session to a file by gpmathis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.