'save stderr with _popen to a variable in C on Windows 10
When I use something like
char result[1000] = "";
char psBuffer[1000];
FILE* pPipe = _popen(command, "rt");
while(fgets(psBuffer, 1000, pPipe) != NULL)
{
strcat(result, psBuffer);
}
printf(result);
Either when command = "echo 123"
or command = "ErrorCommand"
result
only gets the value of the stdout, it never gets the stderr. At first it looks like it does since you get the error printed on your CMD but if you'll save the output and print it or save it to a file you'll see that it only contains the stdout.
Is there a way to make result
also include the stderr?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|