P
P
Programep2015-12-30 23:41:53
Command line
Programep, 2015-12-30 23:41:53

How to transfer Russian characters to _wsystem (c++ windows)?

Good afternoon!
Yes:
windows 7
gcc 5.1
c++ 11
asio
websocketpp
grep.
Required:
Call the grep command, which transmits Russian letters over the network using websocketpp (asio).
Please advise how this can be implemented.
I tried it through the _wsystem function, which I directly passed "grep \"<Russian characters>\" <filename>". That's how everything works. But when I convert a string coming from websocketpp and write it to another one, I get abracadabra.
I convert like this:

std::ostringstream cmdStr;
//переменная from_websocketpp имеет тип std::string
cmdStr << "grep \"" << from_websocketpp << "\" filename.txt>grep.txt";
std::string cmdStr_res = cmdStr.str();

size_t newsize = strlen(cmdStr_res.c_str()) + 1;
wchar_t * wcstring = new wchar_t[newsize];
size_t convertedChars = 0;
mbstowcs_s(&convertedChars, wcstring, newsize, cmdStr_res.c_str(), _TRUNCATE);
_wsystem(wcstring);

UPD1
Here is the output in the console
5c5ec045b4d24f298d4f7a7851995681.pngUPD2
Solved the problem by writing, reading to an intermediate file using std::ofstream and std::ifstream.
Thanks for the hints.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Taratin, 2015-12-31
@Taraflex

Fuck system/_wsystem
www.highscore.de/boost/process/process/tutorials.html

V
VioletGiraffe, 2015-12-31
@VioletGiraffe

In my opinion, it's ok. If it does not work, then you need to look under the debugger, what kind of characters are obtained there.
Is the input UTF-8, or something else?
PS It is not clear why it is so difficult:
instead of
cmdStr_res.length()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question