astronogun has asked for the wisdom of the Perl Monks concerning the following question:
Hi again monks
I would like ask for help on how to output colored text in windows command line? And is it possible to do it without using a module (Win32::Console::ANSI)? Because I'm having problems using that every time I execute the command it displays "Can't locate loadable object for module Win32::Console::ANSI in @INC (@INC contains:"
So I would like to know if it's possible to do it even if I don't use that module... Like I'll just add some elements on the print or printf line.. (I'm thinking that way.. Hope that there's a solution like that hehehe!) If can. Can you give some simple examples..
thanks :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Colored text output in Windows cmd
by zwon (Abbot) on May 12, 2012 at 05:44 UTC | |
"Can't locate loadable object for module Win32::Console::ANSI in @INCThis means that you should install Win32::Console::ANSI. See A Guide to Installing Modules, and A guide to installing modules for Win32 | [reply] |
by astronogun (Sexton) on May 12, 2012 at 06:11 UTC | |
I already did.. but still the error appears.. I'm currently using the Strawberry Perl although I have ActivePerl also installed.. is it some kind of a conflict? | [reply] |
by Anonymous Monk on May 12, 2012 at 07:51 UTC | |
is it some kind of a conflict? No, it means you didn't install the module properly | [reply] |
|
Re: Colored text output in Windows cmd
by roboticus (Chancellor) on May 12, 2012 at 15:35 UTC | |
It's certainly possible, though I would advise using a module to do it (I use Term::ANSIColor). Use google to find the escape codes supported by the windows console, and then write the appropriate functions. I found a reference to ANSI.SYS, which looks like a reasonable reference. Under the "Set Attribute" escape code, after a description of the escape sequence, they list a few examples:
So you should be able to see if they're the correct escape codes with a quickie like so:
Update: Added link for Term::ANSIColor. ...roboticus When your only tool is a hammer, all problems look like your thumb. | [reply] [d/l] [select] |
by BrowserUk (Patriarch) on May 12, 2012 at 15:47 UTC | |
I found a reference to ANSI.SYS, Ansi.sys is an ancient 16-bit driver that hasn't worked with anything since Windows ME. The OP has already found the correct solution(s) -- Win32::Console::Ansi -- all he needs to do is install it/them correctly. Pointing him at ancient 16-bit device drivers is not helpful. If you were a windows users, you'd presumably know that! With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] |
by roboticus (Chancellor) on May 12, 2012 at 15:50 UTC | |
I certainly didn't intend to imply that he should use ANSI.sys, I just thought it was a good reference to the escape codes that (I think) the command console uses. (The tiny example was to let the OP find out if those escape sequences are the correct ones--I suspect so, but am not sure.) I agree that actually trying to use the ANSI.sys device driver would be terrible. ...roboticus When your only tool is a hammer, all problems look like your thumb. | [reply] |
by BrowserUk (Patriarch) on May 12, 2012 at 16:05 UTC | |
|
Re: Colored text output in Windows cmd
by astronogun (Sexton) on May 13, 2012 at 03:18 UTC | |
@roboticus Thanks for the help. I've tried the code that you've just gave and it didn't worked in Perl hehehe! However when I tried that on creating a batch file it worked :) @BrowserUk Right now I'm trying to figure out what is the problem.. I installed the Win32::Console::ANSI and the status is done.. But when I run the code still the error persist.. When I checked my library on Perl Strawberry, there is no Win32::Console::ANSI folder there (even the library of vender and site folders, anyway I just checked them if in case if it was installed there).. Anyway to add some information regarding this it seems the installation progress is installed at the ActivePErl not on the Strawberry Perl... To add up here's the exact message of the problem..
I followed the steps on installing the module (referring to the previous post) but still the problem persist. I'm running Windows 7 Professional 64-bit, and im running perl either command line or the strawberry command line at run as administrator.. Hope you could help me troubleshoot this with this information given.. Thanks to all for the help. | [reply] [d/l] |
by BrowserUk (Patriarch) on May 13, 2012 at 09:11 UTC | |
When you built the module, did you notice this:
Or this:
I don't use Strawberry Perl, so I cannot help you with that. As far as I remember, Win32::Console::ANSI may have come with my AS distribution -- the Win32::Pipe dependancy certainly did -- but even if it didn't and I needed to install it, I'd only have to do:
which took about 12 seconds. With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] [select] |
by Anonymous Monk on May 13, 2012 at 04:02 UTC | |
I followed the steps on installing the module (referring to the previous post) It has been my experience, that whenever perlmonks posters say "I've followed the steps", without showing they've done so (copy/paste of shell session), they missed something simple If you follow Can't locate loadable object for module you can learn from pervious posters why this error happens (copying .pm files) and why you shoudn't do that | [reply] |
by astronogun (Sexton) on May 13, 2012 at 06:23 UTC | |
ok here's what I've done so far.... and it's already OK I've downloaded the Win32-Console-ANSI-1.04.tar.gz file.. then at the command line I typed this: Makefile.pl:
dmake:
dmake test:
dmake install:
To finish I just add Term/ANSI.pm at the C:\strawberry\perl\site\lib (Because it prompt in the cmd that the file can't be located note: on the dmake as I've read on other post it is indicated that for 64-bit running Windows (like me Windows 7) is the best one to use... | [reply] [d/l] [select] |
by syphilis (Archbishop) on May 13, 2012 at 11:14 UTC | |