Hi all,

I have used popen function to run a shell script in my c program..
using that shell script, i write some floating point vale to a temporary file..

Then i tried opening that file using fopen and i used fscanf to read the only floating point value that has been writtten to the file..

First time its correctly reading the value and from then on it reads zero..
But the same code works fine when tested in another system..

Kindly help me out by letting me know where the issue is..

FILE *fpresult, *fp;
fpresult=popen("/bin/sh script.sh","r");

fp=fopen("/tmp/file", "r");
while(fscanf(fp, "%lf", &value)!=EOF)
{

}
printf("Value is %lf", value);

pclose(fpresult);
fclose(fp);

My script.sh will write into the /tmp/file that i have used above..

Recommended Answers

All 2 Replies

Could you post an example of the file or post the shell script?

My shell script will write the following to the (/tmp/file)

<bandwidth>
2323.234

</bandwidth>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.