in reply to Re^4: Saving a Perl session to a file - Win32::Console usabability
in thread Saving a Perl session to a file

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:  <%-{-{-{-<