最近需要进行一下操作:
上位机向 arm开发板发用一个指令,arm接收到这个指令后需要去执行相应的脚本,去完成相应的动作 故而有了下面的代码
callshell.h:
#ifndef __CllShell_H__
#define __CllShell_H__
#define size 100
#define Shell "./test" /*shell脚本所在路径*/
void CallShell (void);
#endif /* __CllShell_H__ */
callshell.c:
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include "CallShell.h"
int main(viod)
{
CallShell ();
return 0;
}
//执行shell脚本函数
void CallShell (void)
{
system(Shell);
FILE *f = popen(Shell,"r");
if(f){
char buf[size];
while(fread(buf,size,1,f)){
printf("%s",buf);
}
pclose(f);
}
}