1
Следующий код производит полный вывод strace. Почему бы не создать только первые 10 символов? Как я могу контролировать вывод strace в моем коде?изменить выход popen и распечатать его на языке c
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#define ARRL 250
void execute_ps(){
int count=0;
char p;
FILE *fp;
char cmd[ARRL];
//insert system command
sprintf(cmd, "strace echo hello");
//open channel to see output of command executed
fp = popen(cmd,"r");
if(fp==NULL){printf("popen err:%s\n",strerror(errno));exit(1);}
while((p=fgetc(fp))!=EOF){
printf("%c",p);
if (count==10){break;}
count++;
}
pclose(fp);
}
int main(int argc, char **argv)
{
execute_ps();
exit(0);
}
спасибо ношение. Это работает. Я пропустил подробности stdout и stderr на странице man. – jdek