首页 > 编程语言 > 详细

C++ 调用脚本

时间:2015-11-12 20:20:00      阅读:324      评论:0      收藏:0      [点我收藏+]
#include <stdio.h>  
#include <stdlib.h>  
#include <sys/wait.h>  
#include <sys/types.h>  
  
int main()  
{  
    pid_t status;  
  
  
    status = system("bash test.sh");  
  
    if (-1 == status)  
    {  
        printf("system error!");  
    }  
    else  
    {  
        printf("exit status value = [0x%x]\n", status);  
  
        if (WIFEXITED(status))  
        {  
            if (0 == WEXITSTATUS(status))  
            {  
                printf("run shell script successfully.\n");  
            }  
            else  
            {  
                printf("run shell script fail, script exit code: %d\n", WEXITSTATUS(status));  
            }  
        }  
        else  
        {  
            printf("exit status = [%d]\n", WEXITSTATUS(status));  
        }  
    }  
  
    return 0;  
}



C++ 调用脚本

原文:http://my.oschina.net/bobwei/blog/529570

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