0

I am executing "codesign -dvv " command through popen. which opens a bidriectional pipe to the child process ( child process for codesign -dvvvv ). when i try reading from the pipe, the output of the command, it reads 0 bytes. following is the code:

\#define MAX_BUF_SIZE 1024
\#define MAX_HASH_SIZE 1024 

snprintf(command, MAX_BUF_SIZE,"codesign -dvv %s", file);
hash = (char *) malloc(MAX_HASH_SIZE);

if (NULL == hash) {
    return NULL;
}

if (!(hfile = popen(command, "r"))){
    return NULL;    
}

while (fgets(temp, MAX_BUF_SIZE, hfile)!=NULL);
printf("sign %lu %s \n",strlen(temp),temp);
strcpy(hash,temp);
pclose(hfile);

In the output i can see the output of codesign command but my program cannot read it.

VikasPushkar
  • 392
  • 3
  • 18

1 Answers1

1

The codesign output is on stderr, not on stdout. popen only accesses stdout.

You should redirect stderr to stdout in your command e.g.:

snprintf(command, MAX_BUF_SIZE,"codesign -dvv %s 2>&1", file);

Hope this allows you to read the output.

Anya Shenanigans
  • 91,618
  • 3
  • 107
  • 122