FILE *stream;//<br>char buffer[12];<br>static int ret = 0;<br>memset(buffer,'\0',sizeof(buffer));//清零<br>system("chmod 777 VerifyNand.sh");//加权限<br>stream = popen("./VerifyNand.sh","r");//运行脚本,用只读方式打开脚本,读取脚本变量<br>printf("script runing...\n");//log,便于掌握程序跑到哪里了<br>if((stream = popen("./VerifyNand.sh","r")) != NULL)//判断是否为空,等于则是打开失败<br>{<br>printf("VerifyNand script error\n");<br>exit(1);<br>}<br>else<br>while(fgets(buffer,sizeof(buffer),stream))//用fgets函数循环读取,自动最后加\0,遇空停止,一行一行读取,这个函数还有待研究,我在这里使用有bug<br>{<br>int x = 0;<br>ret = buffer[x] - '0';//转变成int数值<br>printf("ret = %d\n,ret");<br>if(buffer[x] == '0')//判断从脚本中取出来的数值<br>{<br>printf("Verification FAILED\n");<br>printf("ret = %d\n,ret");<br>pclose(stream);//关闭文件<br>kernel.TaskSleep(10000);//休眠<br>return ret;<br>}<br>else<br>{<br>printf("Verification Passed\n");<br>printf("buffer2 = %c\n",buffer[x]);<br>printf("ret2 = %d\n,ret");<br>kernel.TaskSleep(10000);<br>pclose(stream);<br>x++;<br>return ret;<br>}<br>}<br>这是对于popen函数的应用实例。<br>对于fget