Path: utzoo!attcan!uunet!mailrus!ames!haven!adm!news From: rose@baby.swmed.utexas.edu (Rose Oguz) Newsgroups: comp.unix.questions Subject: C to Shell -- Summary and another question Message-ID: <23498@adm.BRL.MIL> Date: 31 May 90 19:02:40 GMT Sender: news@adm.BRL.MIL Lines: 36 A few people asked me to post the solution to my interfacing C code to a shell script question. The consenus seems to be to use popen(). The syntax follows: FILE *popen(command, type) char *command, *type; command is a shell command line type is I/O mode: r or w So, I used char f_names[20]; char *ret_stat; long stat; FILE *fp ... if ((fp = popen("ls *c", "r") != NULL) { while ((stat=fscanf(fp, "%s", f_names)) != EOF) { ... } } pclose(fp); I also changed the fscanf line to while ((ret_stat=fgets(f_names, 2, fp)) != NULL) Neither seems to work. A file pointer is returned, but the while loop is never executed. For the fscanf, -1 (EOF) is returned and for the fgets, NULL (also, EOF since I opened the file with popen) is returned. I'm running this in my source directory; so, I know that files exist. What am I doing wrong? Any ideas?