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

相关文章:

  • 2022-12-23
  • 2021-12-21
  • 2021-07-25
  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
  • 2021-12-26
猜你喜欢
  • 2022-12-23
  • 2021-12-26
  • 2021-07-23
  • 2022-12-23
  • 2021-12-26
  • 2022-12-23
  • 2021-06-16
相关资源
相似解决方案