#include <stdio.h>
#include <string.h>
#include <errno.h>
int main(int argc,char*argv[])
{
FILE *fstream = NULL;
char buff[1024], command_buf[1024];
memset(buff, 0, sizeof(buff));
memset(command_buf, 0, sizeof(command_buf));
sprintf(command_buf, "%s %s %s", argv[1], argv[2], argv[3]);
if(NULL == (fstream = popen(command_buf,"r")))
{
fprintf(stderr,"execute command failed: %s",strerror(errno));
return -1;
}
while(NULL != fgets(buff, sizeof(buff), fstream))
{
printf("%s",buff);
//printf("buff size: %ld", sizeof(buff));
}
pclose(fstream);
return 0;
}
./a.out diff 1.txt 2.txt
https://blog.youkuaiyun.com/lu_embedded/article/details/78669939