【发布时间】:2018-07-19 22:08:59
【问题描述】:
我目前正在尝试通过调用CreateProcess() 从管道读取 PowerShell 的输出。
startInfo.cb = sizeof(STARTUPINFOW);
startInfo.hStdError = pipes->hErrWrite;
startInfo.hStdOutput = pipes->hOutWrite;
startInfo.hStdInput = pipes->hInRead;
startInfo.dwFlags = STARTF_USESTDHANDLES
BOOL success = CreateProcessW(
L"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
NULL,
NULL,
NULL,
TRUE,
0,
NULL,
NULL,
&startInfo,
&procInfo
);
一切正常,但 PowerShell 的输出具有不同的编码。
我已经使用 CMD 执行了相同的过程。幸运的是,CMD 可以选择使用 /U 参数启动它,该参数以 UTF-16 编码输出。
PowerShell 有类似的东西吗?归根结底,我想将 powershell 的输出存储在 wchar_t 缓冲区中。
【问题讨论】:
-
此处可能重复/相关信息:stackoverflow.com/q/22349139/478656
标签: c powershell encoding