I'm currently trying to read the output of PowerShell from a pipe, by calling CreateProcess()
.
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
);
Everything works fine, but the output of PowerShell has a different encoding.
I already did the same procedure with CMD. Luckily, CMD has the option to start it with the /U
parameter, which encododed the output in UTF-16.
Is there something similiar for PowerShell? At the end of the day, I'd like to store the output of powershell in a wchar_t
buffer.