Console output on Win32?

  • Thread starter Ilya Zakharevich
  • Start date
I

Ilya Zakharevich

Is it possible to use `binmode($fh, SOMETHING)' in Win32 to get "the
expected console-like behaviour" on the handle? Something other API?

I mean something like what I find on:
http://blogs.msdn.com/junfeng/archive/2004/02/25/79621.aspx

(the semantic is to get full unicode text on the console, and text
converted to the current codepage if the output is redirected to a
pipe/file; cp65001 [=UTF-8] not excluded).

Thanks,
Ilya

P.S. Since the code is portable (mp3info2) and very short, I would
prefer a solution as terse as possible...
 
B

Ben Bullock

Is it possible to use `binmode($fh, SOMETHING)' in Win32 to get "the
expected console-like behaviour" on the handle? Something other API?

I mean something like what I find on:
http://blogs.msdn.com/junfeng/archive/2004/02/25/79621.aspx

(the semantic is to get full unicode text on the console, and text
converted to the current codepage if the output is redirected to a
pipe/file; cp65001 [=UTF-8] not excluded).

I'm sorry but I'm not sure I understand exactly your question.

You can find the code page on your system using Win32::Codepage (on
CPAN), and set your binmode to the appropriate encoding.
 
I

Ilya Zakharevich

If you were interested in doing so, writing a :win32console or
:via(Win32::Console) PerlIO layer wouldn't be hard. You would need some
XS to call the W versions of the console functions, of course.

Given that I see Windows a few times in a year, I doubt this is a
viable option. Of course, a pre-cooked solution would be much appreciated...

Thanks,
Ilya
 
I

Ilya Zakharevich

I don't think so. There doesn't appear to be any way to call
WriteConsoleW from perl without wrapping it yourself: AFAICT,
Win32::Console only allows you to call WriteConsoleA, which won't do
what you want.

I knew already that the win32 port of Perl cannot read command-line
arguments, cannot get contents of directories, or open files (as in
http://groups.google.com/group/comp.lang.perl.misc/msg/1fc326742ab7deb2).
Now it is also that it cannot even output to terminal...

I would say that this is a strange state for a >10-years old
commertially-supported port...

Pity,
Ilya

P.S.
The pipe/file part is obviously easy: just use Win32::Console::OutputCP
to get the encoding and binmode($fh, ":encoding(cp$CP)") to encode the
data.

Without correct console output, this does not make any sense... How
it would be better than utf8 output?
 
J

J.I. Asenjo

I knew already that the win32 port of Perl cannot read command-line
arguments, cannot get contents of directories, or open files (as in
http://groups.google.com/group/comp.lang.perl.misc/msg/1fc326742ab7deb2).
Now it is also that it cannot even output to terminal...

o please. Give the full thread then:

http://groups.google.com/group/comp.lang.perl.misc/browse_thread/thread/
0d0080974d220e38/1fc326742ab7deb2?#1fc326742ab7deb2

I do not know what you're talking about, but this smells like a déjà vu ...
 
R

RedGrittyBrick

Ben said:
Quoth RedGrittyBrick said:
(Followup set)

Ilya said:
Is it possible to use `binmode($fh, SOMETHING)' in Win32 to get "the
expected console-like behaviour" on the handle? Something other API?
I don't think so. There doesn't appear to be any way to call
WriteConsoleW from perl without wrapping it yourself: AFAICT,
Win32::Console only allows you to call WriteConsoleA, which won't do
what you want.
I knew already that the win32 port of Perl cannot read command-line
arguments, cannot get contents of directories, or open files (as in
http://groups.google.com/group/comp.lang.perl.misc/msg/1fc326742ab7deb2).
Didn't Sinan answer that?


I find the Win32 port I use does all those things (if I understand
correctly):

C:\> mkdir t
C:\> cd t
C:\t> echo aaa > a.txt
C:\t> echo bbb > b.txt

C:\t> perl -e "print qq(ARGV[0] is '$ARGV[0]'\n)" a.txt
ARGV[0] is 'a.txt'

C:\t> perl -e "opendir $d, '.'; @f = readdir($d); print join ' ', @f"
. .. a.txt b.txt

C:\t> perl -e "open $fh, '<', $ARGV[0]; while(<$fh>) {print}" a.txt
aaa

What have I missed?

None of those files have names that require Unicode. Try it again with
some that do, including names with characters not in your current
codepage.
One of your goals was to get "full Unicode text on the console", do you
mean this sort of thing:

C:\> chcp 65001
Active code page: 65001

C:\> perl -e "binmode(STDOUT, ':utf8'); print qq(abc\x{2116}def\n)"
abcâ„–def

Ilya's aim was to get full Unicode output on the console *without*
changing the codepage. This is possible by calling WriteConsoleW, but
perl doesn't provide any way to call that.

Thanks for clarifying, I now see there are problems as Ilya suggested.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top