首页 > 其他 > 详细

linux C 调用shell程序执行

时间:2014-01-21 19:16:18      阅读:356      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
#include<stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>
#include <sys/prctl.h>
#include <signal.h>

int main()
{
pid_t pid;
char *cmd="bash testshell.sh";
//FILE *fResult=popen("/bin/bash -c testbash.sh","r");
//fResult.close();
pid=fork();
if(pid>0)
        exit(0);
else if(pid==0)
{

        //prctl(PR_SET_PDEATHSIG,SIGKILL);
        execl("/bin/bash","/bin/bash","-c",cmd,NULL);
        exit(0);
}
else if(pid<0)
{
        printf("create faild\n");
        exit(1);
}
return 0;
}
bubuko.com,布布扣

testshell.sh文件

bubuko.com,布布扣
date>testshell_log.log
echo "----------------------------">>testshell_log.log
java -jar TestOracle.jar>>testshell_log.log
echo "----------------------------">>testshell_log.log
date>>testshell_log.log>>testshell_log.log
bubuko.com,布布扣

在shell文件中可以执行各种linux命令,也可以写 if else fi 语句

linux C 调用shell程序执行

原文:http://www.cnblogs.com/ringwang/p/3528163.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!