develooper Front page | perl.perl5.porters | Postings from October 2016

Windows Unicode Environment variables and Input arguments

Thread Next
From:
=?utf-8?B?S2xlbWVuIE1hcmtvdmnEhw==?=
Date:
October 4, 2016 14:10
Subject:
Windows Unicode Environment variables and Input arguments
Message ID:
8085c4a690bf436eb554038efdbaddc1@CORE-EXCH.comtrade.com
Hello,

We use perl as it allows us to use the same scripts on Windows and UX instead of relying on bash scripts for UX and something else for Windows.
We were surprised to find out that we are unable to use Unicode input arguments and environment variables on Windows, like we do on UX platforms.

Example:

1. open windows cmd.exe
2. chcp 65001
3. set VARIABLE=简化字
4. perl somescript.pl 简化字(containing: print $ENV{VARIABLE}, @ARGV)
5. we do not receive proper characters on output

Reasons why this happens are:
-perl.exe uses main(int argc, char **argv) and not wmain(int argc, wchar_t **argv)
-perl.exe calls GetEnvironmentVariableA instead of GetEnvironmentW
-perl.exe calls CreateProcessA instead of calling CreateProcessW and specifying CREATE_UNICODE_ENVIRONMENT, therefore spawned processed by perl will also not have Unicode environment variables and input arguments

On Windows, the Wide versions of all the APIs have to be used to have Unicode support, because Windows Kernel internally uses UCS2/UTF16, so in order to not lose any information, conversions from UTF8 <-> UTF16 and vice versa need to be performed. Using narrow characters in Windows results in loss of Unicode(even though UTF8 is used as input in the console).

We have made these modifications ourselves, but we'd rather see that they get into the next version of perl, so we do not have to do this with each upgrade.
Are there any design limitations to implement this ?

We also noticed that most of the Windows W APIs were removed in favor of A APIs since v5.8.7, where we first encountered these issues. What was the reasoning for it ?

Thanks,
 Klemen

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About