取shell脚本执行的结果


bool OnShellCall(const char *shell_cmd, CString& result)
{
    FILE* pipe = ::popen(shell_cmd, "r");
    if (!pipe)
    {
        return false;
    }
 
    char buffer[256] = {0};
    result = "";
    char * s_read = NULL;
    while(!feof(pipe))
    {
        //s_read return null 或读取完毕
        s_read = fgets(buffer, sizeof(buffer), pipe);
        if (NULL!=s_read)
        {
            result += buffer;
 
        }
        else
        {
            break;
        }
    }
 
    pclose(pipe);
    s_read = NULL;
    return TRUE;
}
View Code

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM