I have the code to check STDERR with 'DRM protected stream detected':
const static char* DRM_TOKEN = "DRM protected stream detected";
const char* source = argv[1];
char tempfile[80];
memset(tempfile, 0, 80);
snprintf(tempfile, 80, "stderr_%lld.log", av_gettime());
freopen(tempfile, "w", stderr);
fflush(stderr);
FILE *fp = fopen(tempfile, "r");
if(fp)
{
char STDERR[256];
while(!feof(fp))
{
memset(STDERR, 0, sizeof(char) * 256);
fgets(STDERR, 256, fp);
if(strstr(STDERR, DRM_TOKEN) != NULL)
{
drm = 1;
break ;
}
}
fclose(fp);
}
It works, but I want to know any directly开发者_如何学JAVA way to read STDERR into char[]. PS. my code will run in linux or macos.
stderr
was reopened in "w"
mode, which is write-only. Judging from your av_gettime
function, it looks like you're using libavcodec
/libavutil
, so instead of writing hideous hacks like this to get the error messages, you should read up on the av_log
system and register your own logging function to override the default behavior of writing diagnostic messages to stderr
.
精彩评论