【发布时间】: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。