Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Win32::Console::ANSI messes up IO

0 views
Skip to first unread message

Filipe Bonjour

unread,
May 10, 2004, 1:05:38 PM5/10/04
to
Hi,

I have some Perl scripts that use Term::ANSIColor to output
error messages in reverse mode. Works fine on Unix, so I was
disappointed to discover that it didn't work on Windows because
cmd.exe doesn't accept ANSI control codes.

Then I found Win32::Console::ANSI, which translates the ANSI
codes into whatever it is that cmd.exe understands. It works,
but unfortunately it brings other problems. It looks like they're
by the module tying STDOUT and STDERR to Win32::Console::ANSI::IO,
which I can't find anywhere.

So I would appreciate any help...

For instance, is there an alternative way of getting reverse video
with cmd.exe?

Or, can I untie the streams, or tie them to another IO module
after writing the reverse text? (I tried, but got nowhere...)

Thanks in advance,

Filipe

Malcolm Dew-Jones

unread,
May 10, 2004, 3:33:30 PM5/10/04
to
Filipe Bonjour (fbon...@nowhere.com) wrote:
: Hi,

: Thanks in advance,

: Filipe

(As an introduction to the subject only) - in old dos systems you load the
ansi.sys driver, and do nothing with the program that sends ansi
sequences.

I thought that with nt there was an equivalent option in the settings for
the console. When that setting is on then the console (i.e. cmd.exe)
recognizes ansi sequences. However I can't easily check right now, so
perhaps I'm wrong.

$0.02

Jean-Louis MOREL

unread,
May 10, 2004, 4:18:56 PM5/10/04
to
Dans l'article <pan.2004.05.10....@nowhere.com>, fbonjour@nowhere
.com a dit...

Hi,

I'm the author of the Win32::Console::ANSI module.

The package Win32::Console::ANSI::IO is in the module ANSI.pm with
Win32::Console::ANSI.

I don't understand the problem. Can you send me a snipet of code with the
bug (and the expected output).

Thanks.

The Win32::Console::ANSI homepage :
http://www.bribes.org/perl/wANSIConsole.html

--
J-L.M.

Filipe Bonjour

unread,
May 10, 2004, 5:02:41 PM5/10/04
to
Dear Jean-Louis,

Thanks for replying! Unfortunately, I only have the code
at the office, so I can't be as specific as I would like
right now.

Basically, I have a script that calls one module called Proc
that uses IPC::Open3 to start child processes. The script also
uses a module Utils which uses Win32::Console::ANSI to print
errors in reverse colour.

The script worked OK until I added the line "use Win32::Console::
ANSI" to Utils. After that, Open3 started throwing errors saying (if
memory serves) that FILENO wasn't defined in Win32::Console::ANSI::IO.

I believe that the error is thrown when Open3 gets to line 313:

311 foreach $fd (@$fds) {
312 $fd->{tmp_copy} = IO::Handle->new_from_fd($fd->{handle},
$fd->{mode});
313 $saved{fileno $fd->{handle}} = $fd->{tmp_copy};
314 }

I can be more specific tomorrow, I'll fetch the details. Anyway,
I'd appreciate any help. Since you're the author of the module,
you might be interested in the version I'm using: 0.05, which I
got from CPAN.

I suspect that I may have done something silly (I have started
programming Perl only about six months ago)...

Thanks!

Filipe

Sisyphus

unread,
May 11, 2004, 3:54:26 AM5/11/04
to
Filipe Bonjour wrote:
> Hi,
>
> I have some Perl scripts that use Term::ANSIColor to output
> error messages in reverse mode. Works fine on Unix, so I was
> disappointed to discover that it didn't work on Windows because
> cmd.exe doesn't accept ANSI control codes.
>

Fwiw, I think Term::ANSIColor will work fine on Windows so long as you
run the script in command.com (not cmd.exe). You would first need to
load the ansi.sys driver as Malcolm indicated.

This is possibly not the solution you're seeking ..... but I believe it
is a solution, nonetheless :-)

Cheers,
Rob

--
To reply by email u have to take out the u in kalinaubears.

Filipe Bonjour

unread,
May 11, 2004, 12:28:28 PM5/11/04
to
Hi,

I tried this very simple script:

#!/usr/bin/perl

#use Win32::Console::ANSI;
use Term::ANSIColor qw(:constants);
use IPC::Open2 qw(open2);

my $pid = open2(*CHLDOUT, *CHLDIN, "notepad");

print REVERSE, "Hello.", RESET;

exit 0;

It works fine without as is, opens a notepad and all. If I uncomment
the "use" line, I get this:

C:\Temp>perl test.pl
open2: Can't locate object method "FILENO" via package
"Win32::Console::ANSI::IO" at C:/Perl/lib/IPC/Open3.pm line 313

On the other hand, if I remove the line with "open2", then "Hello." is
printed in reverse video, as expected.

Any ideas? Do I load the modules properly? I have seen the error on
Windows 2000 and XP.

Thanks!

Filipe

0 new messages