Last active
December 15, 2015 03:29
-
-
Save vshymanskyy/5194697 to your computer and use it in GitHub Desktop.
Cross-platform module to detect and set binmode for standard files;
Requires Encode::Locale to detect console encoding.
Defaults to utf8 I/O.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package StdBinmode; | |
BEGIN | |
{ | |
if ($^O eq 'MSWin32') | |
{ | |
eval <<END; | |
use Encode; | |
use Encode::Locale; | |
binmode(STDIN, ((-t STDIN) and find_encoding('console_in')) ? | |
':encoding(console_in)' : ':encoding(utf8)'); | |
if (find_encoding('console_out')) { | |
binmode(STDOUT, (-t STDOUT) ? ':encoding(console_out)' : ':encoding(utf8)'); | |
binmode(STDERR, (-t STDERR) ? ':encoding(console_out)' : ':encoding(utf8)'); | |
} else { | |
binmode(STDOUT, ':encoding(utf8)'); | |
binmode(STDERR, ':encoding(utf8)'); | |
} | |
END | |
die "$@\n" if $@; | |
} | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment