invoke gpg with popen but cannot get output from the pipe

yuriping at sohu.com yuriping at sohu.com
Mon Jul 4 13:13:46 CEST 2016


Hi all:    I'm using gpg 1.4.10.    Now I want to operate it in my program, and I want to get the output info of gpg from popen, in order that I can process them. Codes like the following:----------------------------------------------------------------#include <stdio.h>#include <sys/wait.h>#include <string.h>#include <stdlib.h>int main(void){    FILE *fpout = popen("gpg --verify yrp.sig yrp", "r");    char buf[1024];    bzero(buf, 1024);    int len = fread(buf, 1024, 1, fpout);    printf("The return of fread = %d, The length of the buf = %d\n", len, strlen(buf));    printf("%s\n", buf);    pclose(fpout);    exit (0);}----------------------------------------------------------------The result didn't appear normal:gpg: Signature made Mon 04 Jul 2016 06:14:44 PM CST using RSA key ID 5FEC9A32gpg: Good signature from "yuriping (3) <yuriping at sohu.com>"The return of fread = 0, The length of the buf = 0But when I popen "ls" as following, ----------------------------------------------------------------#include <stdio.h>#include <sys/wait.h>#include <string.h>#include <stdlib.h>int main(void){    FILE *fpout = popen("ls", "r");    char buf[1024];    bzero(buf, 1024);    int len = fread(buf, 1024, 1, fpout);    printf("The return of fread = %d, The length of the buf = %d\n", len, strlen(buf));    printf("%s\n", buf);    pclose(fpout);    exit (0);}----------------------------------------------------------------It worked properly:The return of fread = 0, The length of the buf = 60popen_lspopen_ls.csignsign.cverifyverify.cyrpyrp.sigIt seems that the output of gpg does not be redirected to the popen command buffer, it still output to the stdout.I want to know what causes the difference, and how to fix it. By the way, this issue appears when "popen("gpg --detach-sign yrp", "w")"Best Regards!



------------------------------------------
搜狐邮箱积分商城积分大派兑,来晚就没了~
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/attachments/20160704/9b66f188/attachment-0001.html>


More information about the Gnupg-users mailing list