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