c程序调用shell脚本主要有以下三种方法,总结中
system:system("/your/path/script.sh -var1 -var2 ... ");
popen:
#include
int main(int argc, char *argv[])
{
char buf[128];
FILE *pp;
if( (pp = popen("ls -l", "r")) == NULL )
{
printf("popen() error!\n");
exit(1);
}
while(fgets(buf, sizeof buf, pp))
{
printf("%s", buf);
}
pclose(pp);
return 0;
}
还有exec比较复杂
阅读(1621) | 评论(0) | 转发(0) |