vmware sdk输出乱码的问题
vmware的sdk里有个坑,考虑下面的代码
use VMware::VIRuntime;
use AppUtil::HostUtil;
Opts::parse();
print("中文");
输出:
ä¸æ��
注释掉Opts::parse(),即可正常输出中文。追溯此问题,查看VMware::VILib.pm
sub parse {
my ($pass_through_option) = @_;
if (!defined($pass_through_option)) {
$pass_through_option = 'no_pass_through';
}
parse_cmdline($pass_through_option);
# bug 182644
$app_name = $0;
$0 = "Hiding the command line arguments";
parse_environment;
parse_config;
parse_stdin;
# user overwrites system encoding
$enc = get_option('encoding');
if ($enc eq "utf8") {
$enc = getencname();
}
if (defined($enc)) { #注意这一段
binmode(STDIN, ":encoding($enc)");
binmode(STDOUT, ":encoding($enc)");
binmode(STDERR, ":encoding($enc)");
}
return;
}
所以如果想恢复正常输出,可以在代码中加上几行:
binmode(STDIN);
binmode(STDOUT);
binmode(STDERR);
感觉可能使用了错误的vmware sdk版本
网友评论