I think there are two reasons why there is no output.
The first is that the time you wait may be too short, causing the pipe to be read before the call is successful, so the output is empty.
The second reason is that the command returns an array of rows. This results in multiple'\0' characters in the returned buffer
, which allows you to truncate subsequent characters when outputting. You can read by character instead Instead of outputting the entire string directly.
Use: WAIT_OBJECT_0 == WaitForSingleObject(piProcInfo.hProcess, 1000)
and: for (int i = 0; i < dwRead; i++) cout << buffer[i];
More reference: “SFC” output redirection formatting issue - Powershell / Batch
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.