【问题标题】:Popen utf8 path打开 utf8 路径
【发布时间】:2016-05-25 06:12:03
【问题描述】:

我想用 _popen

打开 utf8 路径时遇到问题

这是我的代码:

char buf1520[1500];
string testme;
const char * sroot2 = getenv ("systemroot");
string md5cmd2 = sroot2;
md5cmd2 += "\\System32\\certutil -hashfile ";
md5cmd2 += "C:\\Users\\Vuzee\\Desktop\\testč\\test.jar";
cout << md5cmd2 << endl;
md5cmd2 += " MD5";
const char* md5cmdnovo2 = md5cmd2.c_str();
FILE *p1502 = _popen(md5cmdnovo2, "r");

for (size_t count; (count = fread(buf1520, 1, sizeof(buf1520), p1502));)
    testme += string(buf1520, buf1520 + count);
    _pclose(p1502);

cout << "HASH:" << testme << endl;
cin.ignore();

在这条 cout 另一条路径上,我得到这个输出:C:\Windows\System32\certutil -hashfile C:\Users\Vuzee\Desktop\testÄ\test.jar

所以我认为问题是因为字符串无法保存 UTF8 字符,那么我该如何解决这个问题并在 popen 中调用它?

最后我得到:

HASH:CertUtil: -hashfile command FAILED: 0x80070003 (WIN32: 3)
CertUtil: The system cannot find the path specified.

【问题讨论】:

  • 是什么让您认为 UTF-8 应该在 Windows API 中工作?
  • 在进行文件系统调用之前,您需要将 UTF-8 转换为 UTF-16 LE。

标签: c++ gcc utf-8


【解决方案1】:

您的应用程序可以将字符串存储为 UTF-8,但 Windows 操作系统有两种应用程序接口风格 — UTF-8 也不是。

您可以使用处理wchar_t(宽字符)的_wopen 函数使您的应用程序工作。首先,您必须将md5cmd2 中的string 值转换为宽字符串(无法转换为char*)。

进一步阅读:

【讨论】:

    猜你喜欢
    • 2019-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-25
    • 2016-07-13
    • 2021-04-28
    • 2015-07-30
    • 1970-01-01
    相关资源
    最近更新 更多