美文网首页
2020-05-12

2020-05-12

作者: 匿名天使 | 来源:发表于2020-05-12 15:18 被阅读0次

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版本

相关文章

网友评论

      本文标题:2020-05-12

      本文链接:https://www.haomeiwen.com/subject/kvvbnhtx.html