简体   繁体   中英

reading codesign -dvvvv output from terminal into a cpp program

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.

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

You should redirect stderr to stdout in your command eg:

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

Hope this allows you to read the output.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM