取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