elmachin has asked for the wisdom of the Perl Monks concerning the following question:

What is causing $CONSOLE->Attr to not work after capture_exec?
I use terminal color change to highlight errors during production tests.

The issue is that after I use "capture_exec" the colors no longer change. I'm assuming it has something to do with the execution of the code in another instance or something ?.?.

In the code below the output is
WHITE text color white
GREEN text color green
WHITE text color green

Thanks for the help you guys have saved by bacon a ton over the years
Matt-rookie

use strict; use warnings; use IO::CaptureOutput qw/capture_exec/; use Win32::Console; use vars qw($CONSOLE $attr); $CONSOLE = Win32::Console->new(STD_OUTPUT_HANDLE); $attr = $CONSOLE->Attr(); #get current console colors $CONSOLE->Attr($FG_WHITE | $BG_BLACK); #wht text on blk print "white\n"; $CONSOLE->Attr($FG_GREEN | $BG_BLACK); #grn text on blk print "green\n"; my ($stdout, $stderr, $success, $exit_code) = capture_exec( "dir" ); $CONSOLE->Attr($FG_WHITE | $BG_BLACK); #grn text on blk print "white\n";

Replies are listed 'Best First'.
Re: IO::CaptureOutput Win32::Console compatibility
by poj (Abbot) on Mar 30, 2017 at 17:48 UTC

    Works OK for me

    Windows 10 Pro 64bit
    Perl Binary build 1601 296175 provided by ActiveState
    $IO::CaptureOutput::VERSION = 1.1104
    $Win32::Console::VERSION    = 0.10 (corrected)
    
    poj

      Interesting,
      I'm using Win7 Pro 64bit
      Perl Binary build 1604 298023 from ActiveState
      $IO::CaptureOutput::VERSION = 1.1104
      $Win32::Console::VERSION = 0.10

      I tried winxp
      Perl 5_22_1
      $IO 1.1104
      $Win32 0.10

      I also tried on 2 other computers with Strawberry Perl and both had the same issue
      Strawberry 5_24_1 with the packages the same versions

        Tried it on my ASUS Netbook Win 7 and I get the same result as you. That's with 5.14 activestate.

        poj

      Where'd you get Win32::Console v0.11? cpan and metacpan both list v0.10.

      I tried in Win7 64, strawberries v5.24.0_32, v5.24.0_64, and v5.24.1_64, with IO::CaptureOutput v1.1104 and Win32::Console v0.10: all three replicate elmachin's behavior.

        Sorry, typo should be 0.10