Popen utf8 path

0

i have a problem when i want to open a utf8 path with _popen

So here is my code:

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();

On this cout afther path, i get this output:C:\Windows\System32\certutil -hashfile C:\Users\Vuzee\Desktop\testÄ\test.jar

So i think problem is because string cannot save UTF8 chars, so how can i fix that and call it in popen?

and for last cout i get:

HASH:CertUtil: -hashfile command FAILED: 0x80070003 (WIN32: 3)
CertUtil: The system cannot find the path specified.
c++
gcc
utf-8
asked on Stack Overflow Feb 14, 2016 by Dushan01

1 Answer

0

Your application may store the string as UTF-8, but the Windows operating system has two flavors of application interface — neither is UTF-8.

You can make your application work using the _wopen function, which handles wchar_t (wide-characters). As a start, you will have to convert the string value in md5cmd2 to a wide-string (casting to char* will not work).

Further reading:

answered on Stack Overflow Feb 14, 2016 by Thomas Dickey • edited May 23, 2017 by Community

User contributions licensed under CC BY-SA 3.0