首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

system()返回值跟WEXITSTATUS() 返回值

2013-10-12 
system()返回值和WEXITSTATUS() 返回值string rsync /bin/rsync.shint status system(rsync_c.c_st

system()返回值和WEXITSTATUS() 返回值


    string rsync = "/bin/rsync.sh"; 
    int status = system(rsync_c.c_str());
    if(-1 == status)
        m_logger.warn("system rsync_s error. status[%d]",status);
    else
    {   
        if(WIFEXITED(status))
        {   
            if(0 == WEXITSTATUS(status))
                m_logger.debug("rsync[%s]",rsync_c.c_str()); // 1
            else
                m_logger.warn("run shell script rsync_s fail.exit code [%d]",WEXITSTATUS(status)); // 2
        }   
        else
            m_logger.debug("exit status[%d]",WEXITSTATUS(status));
    }


看一帖子说上面才是判断system执行脚本是不是正确的逻辑,仅 1时,才为正常。

现象是:当文件少的时候,执行 1;当文件多(5000个文件以上)的时候,执行2,返回码为 23,但是这时候rsync也是ok的。

WEXITSTATUS 是返回子进程的退出码。

该不该上  if(0 == WEXITSTATUS(status))  这个判断呢?

请指教! 谢谢!

WEXITSTATUS system(.sh)
[解决办法]
int system(const char *s)
system passes the string s to the environment for execution. If s is NULL, system returns non-zero if there is a command processor. If s is not NULL, the return value is implementation-dependent.
[解决办法]
判断system执行脚本是不是正确的逻辑,仅 1时,才为正常
这个应该不对吧!
system()调用成功则最后会返回执行shell命令后的返回值的

看看这个吧,有详细说明
http://blog.csdn.net/kulung/article/details/6524000

热点排行
Bad Request.