linux 系统中调用执行脚本

来源:互联网 发布:元数据由什么存储 编辑:程序博客网 时间:2024/06/05 10:34

最近需要进行一下操作:

上位机向 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);
 }
}

 

0 0
原创粉丝点击