C to Shell -- Summary and another question
Kartik Subbarao
subbarao at phoenix.Princeton.EDU
Fri Jun 1 06:58:45 AEST 1990
In article <23498 at adm.BRL.MIL> rose at baby.swmed.utexas.edu (Rose Oguz) writes:
>
>So, I used
> char f_names[20]; /* Make this 21 */
> char *ret_stat;
> long stat;
> FILE *fp;
> ...
> if ((fp = popen("ls *c", "r") != NULL)
/* Need an extra ')' here ---^ */
{
/* Ugly fscanf code deleted */
> while ((ret_stat=fgets(f_names, 2, fp)) != NULL)
> /* ^^^ 2?! Don't you mean 20? */
}
> pclose(fp);
>
>
>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?
I have no idea how this passed the compiling stage of your computer. The way
it looks now, its as if you are saying fp = (popen("ls *c", "r") != NULL),
because != has higher precedence than =. And so our compiler will gripe
because you are trying to assign the value of int to a FILE *.
As to fgets, it should now work -- I hope you meant 20 instead of 2!
-Just another popen() hacker,
Kartik
--
subbarao@{phoenix,bogey or gauguin}.Princeton.EDU -|Internet
kartik at silvertone.Princeton.EDU (NeXT mail) -|
subbarao at pucc.Princeton.EDU - Bitnet
More information about the Comp.unix.questions
mailing list