c++ 調用php


int _System(const char * cmd, std::string& strRet)
{
    FILE * fp;
    char * p = NULL;
    int res = -1;

    if ((fp = _popen(cmd, "r")) == NULL)
    {
        printf("popen Error!\n");
        return -2;
    }
    else
    {
        char tempStr[1024];
        memset(tempStr, 0, 1024);
        while (fgets(tempStr, 1024, fp) != NULL)
        {
            strRet += tempStr;
        }

        _pclose(fp);
        return 0;
    }
}

 

php代碼,文件命名為test.php:

<?php
$arg = $argv[1];
echo $arg;
?>

 

c++調用:

_System("php test.php helloworld");

 

c++輸出結果:

helloworld

 

轉載請注明出處,from博客園HemJohn


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM