popen() problem!

Hi!

I had a strange problem in using popen(). The relative codes are as follows:

FILE *fp = popen( “sin”,“r” );
if( fp != NULL ) {
char buf[80];
while( fgets( fp, 80, buf ) ) {
// do something here

}

pclose( fp );
}

When I use the above codes in a independ test program, it works well. BUT
when I integrated in my embeded applications, it does not work any more. I
have tested the return value fp, it’s no NULL, but fgets(fp, 80, buf) always
returns 0 while errno is also 0 and I have verified that there is no other
pipe in the same process. So my question is: what factors can affect fgets()
after popen()?

Waiting for your helps.

regards,


Yang WANG
BCI sa

“Yang WANG” <wy@bcisa.com> wrote in message
news:8qad7n$3ia$1@front4m.grolier.fr

Hi!

I had a strange problem in using popen(). The relative codes are as
follows:

FILE *fp = popen( “sin”,“r” );
if( fp != NULL ) {
char buf[80];
while( fgets( fp, 80, buf ) ) {
// do something here

}

pclose( fp );
}

Are you playing with buffering flags (setvbuf(), setbuf())

I’m assuming you want to get information out of sin. Most of
sin information is available via an api or system message, much much
more easier then parsing sin output :wink: qnx_osinfo() and qnx_psinfo()

When I use the above codes in a independ test program, it works well. BUT
when I integrated in my embeded applications, it does not work any more. I
have tested the return value fp, it’s no NULL, but fgets(fp, 80, buf)
always
returns 0 while errno is also 0 and I have verified that there is no
other
pipe in the same process. So my question is: what factors can affect
fgets()
after popen()?

Waiting for your helps.

regards,


Yang WANG
BCI sa
\