我尝试使用CreateProcess从MFC应用程序启动控制台应用程序。
CString变量包含应用程序名和命令行arg,该命令行是中文UTF8文件名。
文件名不以UTF8格式传递,应用程序失败。
我怎样才能以正确的方式发送命令?
BOOL bRetVal = ::CreateProcess( NULL,
cmd.GetBuffer(m_strProg.GetLength()), // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
0, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi // Pointer to PROCESS_INFORMATION structure.
);
发布于 2012-02-02 13:50:59
假设您正在以多字节模式编译(而不是unicode)。
CT2W path(m_strProg);
CreateProcessW(path, ...);
发布于 2012-02-02 15:52:23
根据编译器设置的不同,您将调用CreateProcessA
(在当前代码页中使用char
字符串),或者调用在Unicode 16中使用wchar_t
字符串的CreateProcessW
。这两种方法都不能将UTF-8字符串作为输入处理.
您应该将UTF-8字符串转换为UTF-16,然后从该字符串构建命令行。
发布于 2012-02-02 11:52:16
只是说你有两个否定句,在英语中,这使它成为一个积极的-所以你是说,事实上,通过UTF8。无论如何,您还需要阅读http://www.joelonsoftware.com/articles/Unicode.html,您需要更改您的区域设置和代码页,类似于Unicode characters in Windows command line - how?。
https://stackoverflow.com/questions/9111743
复制相似问题