从C ++程序调用PHP脚本 [英] Calling a PHP script from a C++ Program

查看:94
本文介绍了从C ++程序调用PHP脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从C ++程序调用PHP脚本.例如,这是一个示例C ++程序:

I'm attempting to call a PHP script from a C++ program. For instance, here is an example C++ program:

#include <iostream>
#include <cstdlib>

using namespace std; 

int main() {

cout << std::system("test.php");

return 0;
}

该程序正在调用一些脚本"test.php",其结构可能如下:

This program is calling some script "test.php" which might be structured like this:

<?php
echo "Hello";
?>

运行C ++代码时,我得到以下信息:

When running the C++ code, I get the following:

sh: 1: test.php: not found.

现在很明显要检查的是文件是否在同一目录中(实际上是),但是错误仍然存​​在.关于我可能会如何做这样的事情的任何反馈意见?

Now the obvious thing to check is if the files are in the same directory (they indeed are), however the error still persists. Any feedback on how I might go about doing something like this?

谢谢.

推荐答案

尝试:

cout << std::system("php -f test.php");

如果要将php脚本作为命令行脚本执行,则必须在php脚本的第一行添加一个shebang行.像

If you want to execute a php script as a command line script you must add a shebang line at the first line of you php script. Like

#!/usr/bin/php

这篇关于从C ++程序调用PHP脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆