in reply to Saving a Perl session to a file
Update: Caution: This is only tested under Windows 7!
Play around with Win32::Console. This script
Script: cap_con_1.pl
use warnings; use strict; use Win32::Console 'STD_OUTPUT_HANDLE'; 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; print qq($left, $top, $right, $bottom \n); my $rect = $con_current->ReadRect($left, $top, $right, $bottom); $rect or die 'read Win32::Console failed'; $rect =~ s{ \0\a\0 } ''xmsg; $rect =~ s{ [ ]+ \z } ''xmsg; dd $rect; print qq{======\n$rect\n======\n};
c:\@Work\Perl\monks\gpmathis>perl -wMstrict -le "print qq{\nHow old are you?: }; my $age = <STDIN>; my $year = 2017 - $age; print qq{You were born in $year\n}; " How old are you?: 42 You were born in 1975 c:\@Work\Perl\monks\gpmathis>perl cap_con_1.pl 0, 0, 99, 59 " c:\\\@Work\\Perl\\monks\\gpmathis>perl -wMstrict -le \"print qq{\\nHow old are you?: }; my \$age = <STDIN>; my \$year = 2017 - \$age; print qq{You were born in \$year\\n}; \" How old are you?: 42 You were born in 1975 c:\\\@Work\\Perl\\monks\\gpmathis>perl cap_con_1.pl 0, 0, 99, 59" ====== c:\@Work\Perl\monks\gpmathis>perl -wMstrict -le "print qq{\nHow old are you?: }; my $age = <STDIN>; my $year = 2017 - $age; print qq{You were born in $year\n}; " How old are you?: 42 You were born in 1975 c:\@Work\Perl\monks\gpmathis>perl cap_con_1.pl 0, 0, 99, 59 ====== c:\@Work\Perl\monks\gpmathis>
Update: Use cls to begin a "session". You should be able to futz around with the captured $rect string to clip off the invocation of the script at the end. Also, the Perl script can be converted into a .bat file with the venerable Windows Batch Wrapper trick:
File: capsess.bat
@REM = 'windows batch wrapper @ECHO off perl %0.bat goto BYEBYE ' if 0; use warnings; use strict; use Win32::Console 'STD_OUTPUT_HANDLE'; 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; my $width = $right - $left + 1; my $rect = $con_current->ReadRect($left, $top, $right, $bottom); $rect or die 'read Win32::Console failed'; $rect =~ s{ \0\a\0 } ''xmsg; $rect =~ s{ [ ]+ \z } ''xms; $rect =~ s{ .{$width} \z } ''xms; print qq{======\n$rect\n======\n}; __END__ :BYEBYE
c:\@Work\Perl\monks\gpmathis>--- c:\@Work\Perl\monks\gpmathis>perl -wMstrict -le "print qq{\nHow old are you?: }; my $age = <STDIN>; my $year = 2017 - $age; print qq{You were born in $year\n}; " How old are you?: 42 You were born in 1975 c:\@Work\Perl\monks\gpmathis>capsess ====== c:\@Work\Perl\monks\gpmathis>--- c:\@Work\Perl\monks\gpmathis>perl -wMstrict -le "print qq{\nHow old are you?: }; my $age = <STDIN>; my $year = 2017 - $age; print qq{You were born in $year\n}; " How old are you?: 42 You were born in 1975 ====== c:\@Work\Perl\monks\gpmathis>
Give a man a fish: <%-{-{-{-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Saving a Perl session to a file
by Discipulus (Canon) on Apr 14, 2017 at 08:18 UTC | |
by AnomalousMonk (Archbishop) on Apr 14, 2017 at 14:59 UTC | |
by Discipulus (Canon) on Apr 15, 2017 at 11:52 UTC | |
by AnomalousMonk (Archbishop) on Apr 15, 2017 at 18:54 UTC | |
|
Re^2: Saving a Perl session to a file
by marinersk (Priest) on Apr 14, 2017 at 02:59 UTC |